简体   繁体   English

如何在PCL项目中对Xamarin.Forms.GoogleMaps Pin进行群集

[英]How to Cluster Xamarin.Forms.GoogleMaps Pin in PCL Project

Since I am doing a map based cross-platform project on Xamarin, And I'm stuck to the point where I need to cluster markers when zooming out. 由于我正在Xamarin上进行基于地图的跨平台项目,因此我被困在缩小时需要对标记进行聚类的地步。 things I had tried: 我尝试过的事情:

  • GoogleMapUtility Project. GoogleMapUtility项目。
  • And tried to use ClusterManager of GoogleMapUtility through dependency. 并尝试通过依赖关系使用GoogleMapUtility的ClusterManager。 so that I can add a pin to cluster manager From PCL project. 这样我就可以向PCL项目的集群管理器添加一个引脚。 But to initialize cluster manager I need a Native Map instance ie Android.Gms.Maps.GoogleMap.(don't know how to get) 但是要初始化集群管理器,我需要一个本地地图实例,即Android.Gms.Maps.GoogleMap。(不知道如何获取)

I know I can achieve it with that with custom map renderer, but I cant do that coz. 我知道我可以使用自定义地图渲染器来实现,但是我做不到。 a lot of code related to map is already written, I don't want to rewrite a Code. 已经编写了许多与地图有关的代码,我不想重写代码。 So Is there any possibility that I can get a native instance of the map that I can use on dependency service. 那么,是否有可能我可以在依赖服务上使用地图的本机实例。

I created CustomRenderer For Map without creating a customMap class at PCL (inherit Map class) the code is below. 我创建了CustomRenderer For Map,而没有在PCL(继承Map类)上创建customMap类,代码如下。 but it's not get triggered. 但不会被触发。 What wrong I am doing here... 我在这里做什么错...

custom renderer code: 自定义渲染器代码:

[assembly: ExportRenderer(typeof(Map), typeof(MarkerClusterRenderer))]
namespace SamplingApp.Droid.CustomRenderers
{
    public class MarkerClusterRenderer : MapRenderer
    {
        ClusterManager _clusterManager;
        protected override void OnMarkerCreated(Pin outerItem, Marker innerItem)
        {
            base.OnMarkerCreated(outerItem, innerItem);
            AddToMarkerCluster();
        }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
        }
        protected override void OnElementChanged(ElementChangedEventArgs<Map> e)
        {
            base.OnElementChanged(e);
        }

    public void AddToMarkerCluster()
    {
        _clusterManager = new ClusterManager(Android.App.Application.Context, NativeMap);
        //[do other things here]
    }

}
}

since I am is new to xamarin. 因为我是xamarin的新手。 little guidance is appreciated. 很少的指导表示赞赏。 am I in the right direction? 我的方向正确吗?

Thank you in advance. 先感谢您。 and sorry for my English. 对不起,我的英语。

I created CustomRenderer For Map without creating a customMap class at PCL (inherit Map class) the code is below. 我创建了CustomRenderer For Map,而没有在PCL(继承Map类)上创建customMap类,代码如下。 but it's not get triggered. 但不会被触发。 What wrong I am doing here... 我在这里做什么错...

If you want to customize the map, you need to create a custom class for map control in PCL: 如果要自定义地图,则需要为PCL中的地图控件创建自定义类:

public class CustomMap:Map
{

}

And use it in xaml: 并在xaml中使用它:

<local:CustomMap WidthRequest="320" HeightRequest="200"
        x:Name="MyMap"
        IsShowingUser="true"
        MapType="Hybrid"/>

And renderer: 和渲染器:

[assembly:ExportRenderer(typeof(SamplingApp.CustomMap),
  typeof(MarkerClusterRenderer))]
namespace SamplingApp.Droid.CustomRenderers
{
    public class MarkerClusterRenderer:MapRenderer
    {
        ...

Then, your renderer's codes will be triggered correctly. 然后,渲染器的代码将被正确触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用 Xamarin.Forms.GoogleMaps 单击图钉后显示弹出窗口 - How to show a popup window after a pin is clicked with Xamarin.Forms.GoogleMaps 无法平移或缩放 Xamarin.Forms.GoogleMaps - Unable to pan or zoom Xamarin.Forms.GoogleMaps 如何使用Xamarin.Forms.GoogleMaps将地图的纬度和经度转换为像素坐标? - How can you translate a map latitude and longitude to a pixel coordinate using Xamarin.Forms.GoogleMaps? Xamarin.Forms.GoogleMaps iOS System.NullReferenceException - Xamarin.Forms.GoogleMaps iOS System.NullReferenceException 如何将MongoDB与Xamarin.Forms PCL一起使用(共享项目) - How to use MongoDB with Xamarin.Forms PCL (Shared project) Xamarin表单:如何在PCL项目中使用嵌入式资源进行图像处理 - Xamarin Forms: How to use Embedded Resources in PCL Project for Image 如何在Xamarin Forms项目中使用Couchbase.Lite-PCL? - How to use Couchbase.Lite-PCL in a Xamarin Forms project? 如何在Xamarin Forms PCL项目上阅读文本文件? - How to read a text file on Xamarin Forms PCL project? Xamarin从列表到图钉和信息窗口形成GoogleMaps数据 - Xamarin Forms GoogleMaps data from list to pin and info window Xamarin Forms-PCL项目无法启动该应用 - Xamarin Forms - PCL project The app could not be started
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM