【问题标题】:Proper way to use android map renderer?使用android地图渲染器的正确方法?
【发布时间】:2015-04-15 01:59:32
【问题描述】:

尝试在 android 的地图上添加 Tap 处理程序时,要继承的正确对象是什么?我尝试过使用 MapView、MapRenderer、MapActivity、Overlay 等等。

CustomMapRenderer.cs

完全错误,但显示了我一直在尝试的内容。

using Xamarin.Forms;
using nuMaps;
using nuMaps.Droid;
using Android.Gms.Maps;
using System;
using Xamarin.Forms.Maps.Android;
using Xamarin.Forms.Platform.Android;
using Android.App;
using Xamarin.Forms.Maps;
using Android.Widget;
using Android.GoogleMaps;
namespace nuMaps.Droid
{
    public class CustomMapRenderer  MapActivity
    {
        public override bool OnTouchEvent (Android.Views.MotionEvent e, Android.GoogleMaps.MapView mapView)
        {
            Console.WriteLine (e.Action);
            return base.OnTouchEvent (e, mapView);
        }
    }
}

MapPage.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:nuMaps;assembly=nuMaps"
    x:Class="nuMaps.MapPage">
    <ContentPage.Content>
        <AbsoluteLayout>
            <local:CustomMap
                x:Name="MyMap"
                IsShowingUser="true"
                MapType="Hybrid"
                AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
                AbsoluteLayout.LayoutFlags="All"
            />
        </AbsoluteLayout>
    </ContentPage.Content>
</ContentPage>

【问题讨论】:

    标签: c# android mobile xamarin


    【解决方案1】:

    我实现了简单的扩展地图控件来测试自定义地图渲染器。你可以看看here。不确定这是否是您需要的。此类的唯一目的是为所有三个平台提供点击位置。这是纯示例代码,不适用于生产,对我来说很好,但如果您有任何问题,请告诉我。

    【讨论】:

    • 这似乎工作得很好,而且相当彻底!太感谢了!我没有在 ExtendedMap/ExtendedMap.cs/OnTap(TapEventArgs e) 中调用 handler(this,e) 的唯一部分。这是某种需要发生的保留逻辑吗?
    • 其实我是在更深入地研究之后才发现的。看起来渲染只是内联类 TapEventArgs 的一个实例。再次感谢!
    • 处理程序仅用于安全事件调用stackoverflow.com/questions/3668953/…
    猜你喜欢
    • 2019-07-26
    • 1970-01-01
    • 2022-08-05
    • 2020-04-06
    • 2017-07-14
    • 2015-05-14
    • 2018-12-25
    • 1970-01-01
    • 2015-08-23
    相关资源
    最近更新 更多