如何在Xamarin中实现Google Maps的标记集群 [英] How to implement Marker Clustering for Google Maps in Xamarin

查看:77
本文介绍了如何在Xamarin中实现Google Maps的标记集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中成功实现了Google Maps.我必须为 Xamarin Android实施Marker Clustering.

I have implemented Google Maps successfully in my App. I have to implement Marker Clustering for Xamarin Android.

链接在此给出了有关以下内容的很好的解释如何实现,但我不明白如何引用该程序包.

The link here gives a good explanation regarding how to implement but i am not able to understand how to refer the package.

我的源文件很少,但是它不起作用,因为我不知道如何引用jar文件.我得到的文档与Java有关,但与C#不相关.以下是一些链接:

I got few source files but it is not helping as i am not aware how to refer the jar files. The documents i got is related to Java but not C#. Here are the few links:

https://github.com/googlemaps/android-maps-utils https://forums.xamarin.com/discussion/13569/google-maps-android-api-utility-library-support/p2?

推荐答案

您要使用包含android-maps-utils.aar文件的Xamarin.Android绑定项目.

You want to use the Xamarin.Android Binding project that includes the android-maps-utils.aar file.

注意:我有分叉的Github较旧的仓库,其中包括一个绑定项目和示例,并将其更新为android-maps-utils.aar的最新版本(本文中的v0.4.3).

Note: I have forked an older Github repo that included a binding project and example and updated it to the latest version of android-maps-utils.aar (v0.4.3 as of this post).

只需克隆即可回购并将整个GoogleMapsUtility项目复制到您的Xamarin.Android解决方案中,然后将其添加到您的解决方案中(通过添加现有项目").

Just clone that repo and copy the entire GoogleMapsUtility project into your Xamarin.Android solution and add that to your solution (via Add Existing Project).

然后,您可以像平常一样创建Google Map,即:

Then you can create a Google Map like you would normally, i.e.:

GoogleMapOptions mapOptions = new GoogleMapOptions()
    .InvokeMapType(GoogleMap.MapTypeNormal)
    .InvokeZoomControlsEnabled(true)
    .InvokeMapToolbarEnabled(true)
    .InvokeZoomGesturesEnabled(true)
    .InvokeRotateGesturesEnabled(true)
    .InvokeCompassEnabled(true);

然后,您可以将地图标记添加到ClusterManager并让其管理聚类:

Then you can add your Map markers to the ClusterManager and let it manage the clustering:

_clusterManager = new ClusterManager(this, _map);
_clusterManager.SetOnClusterClickListener(this);
_clusterManager.SetOnClusterItemClickListener(this);
_map.SetOnCameraChangeListener(_clusterManager);
_map.SetOnMarkerClickListener(_clusterManager);

我修改了原始示例,以在日志中创建20个标记.螺旋图案以各种缩放级别测试集群:

I modified the original example to create 20 markers in a log. spiral pattern to test the cluster at various zoom levels:

private void AddClusterItems()
{
    double lat = 47.59978;
    double lng = -122.3346;

    var items = new List<ClusterItem>();

    // Create a log. spiral of markers to test clustering
    for (int i = 0; i < 20; ++i)
    {
        var t = i * Math.PI * 0.33f;
        var r = 0.005 * Math.Exp(0.1 * t);
        var x = r * Math.Cos(t);
        var y = r * Math.Sin(t);
        var item = new ClusterItem(lat + x, lng + y);
        items.Add(item);
    }
    _clusterManager.AddItems(items);
}

这篇关于如何在Xamarin中实现Google Maps的标记集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆