【问题标题】:Having map markers appear/disappear at certain zoom levels地图标记在某些缩放级别出现/消失
【发布时间】:2014-09-10 05:28:16
【问题描述】:

我正在制作一个应用程序,它将许多独特的标记绘制到地图片段(60 个标记)/我为此使用 ArrayList 和 for 循环来绘制它们。

我遇到的问题是,在缩小地图时,地图非常混乱,而且滞后。我想找到一种方法让标记在缩小时消失,例如在 11 级,然后从 10 级放大。我该怎么做?

// Get a handle to the xml Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

ArrayList<LatLng> tree = new ArrayList<LatLng>()

tree.add(new LatLng(48.617515, -3.945385));
tree.add(new LatLng(49.617515, -3.945385));
... //x58

for (int i = 0; i < camLoc.size(); i++) {      //for loop to add the LatLng data to the array list
         map.addMarker(new MarkerOptions()
        .position(camLoc.get(i)));         
 }
}

【问题讨论】:

  • onCameraChanged 被调用时更新你的标记

标签: android google-maps-api-3 google-maps-markers


【解决方案1】:

Google 发布了一个库,在设置时,缩小时会自动聚集标记。它是 Google Maps Android API 实用程序库的一部分,available here。您可以找到clustering here 的设置指南。我个人在我的应用程序中使用了它(在尝试设置其他库数月之后)并取得了很大的成功。但是,在对许多项目进行聚类/去聚类时会有一点延迟(不过,我的地图上有超过 1000 个项目,所以您可能不会遇到同样的问题)。

请务必注意,您需要创建 ClusterItem 的自定义实现并将这些对象传递给集群器,而不是直接通过 GoogleMap 设置标记。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-04
    • 2018-10-07
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 2017-10-14
    • 1970-01-01
    相关资源
    最近更新 更多