2013-04-14 29 views
2

我試圖找到一種方法來管理我的應用程序中的Android地圖(v2)實現中的標記。我希望能夠繪製位於可視邊界內的標記,同時僅顯示某個縮放級別以上的標記。這似乎是一個普遍的問題。所以,我問是否有人使用像標記管理器庫之類的東西。只是爲了讓事情變得簡單,而且我不必從頭開始。謝謝。是否有Android谷歌地圖v2標記管理器?

回答

2

還不是經理,但您可能需要檢查Android Maps Extensions,它具有羣集功能。

編輯:

在AME,可見區域內的繪圖標記可以通過以下方式實現:

map.setClustering(new ClusteringSettings().addMarkersDynamically(true)); 

map.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true)); 

如果你不想集羣但只在添加多個標記時優化案例。

僅當您點擊某個縮放級別時才顯示標記尚未完全實施,但已請求here

1

我意識到這個問題很老,但如果有人仍然有同樣的問題,可以使用Google Maps Android Marker Clustering Utility。應採取
步驟如下:

  1. 實施ClusterItem以表示地圖上的標記。簇項以LatLng對象的形式返回標記的位置。
  2. 添加新的ClusterManager以根據縮放級別對羣集項目(標記)進行分組。
  3. 將映射的OnCameraChangeListener()設置爲ClusterManager,因爲ClusterManager實現了偵聽器。
  4. 如果您想添加特定功能來響應標記點擊事件,請將映射的OnMarkerClickListener()設置爲ClusterManager,因爲ClusterManager實現了偵聽器。
  5. 將標記送入ClusterManager。

實現示例:

public class MyItem implements ClusterItem { 
    private final LatLng mPosition; 

    public MyItem(double lat, double lng) { 
     mPosition = new LatLng(lat, lng); 
    } 

    @Override 
    public LatLng getPosition() { 
     return mPosition; 
    } 
} 


private void setUpClusterer() { 
    // Declare a variable for the cluster manager. 
    private ClusterManager<MyItem> mClusterManager; 

    // Position the map. 
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); 

    // Initialize the manager with the context and the map. 
    // (Activity extends context, so we can pass 'this' in the constructor.) 
    mClusterManager = new ClusterManager<MyItem>(this, getMap()); 

    // Point the map's listeners at the listeners implemented by the cluster 
    // manager. 
    getMap().setOnCameraChangeListener(mClusterManager); 
    getMap().setOnMarkerClickListener(mClusterManager); 

    // Add cluster items (markers) to the cluster manager. 
    addItems(); 
    } 

private void addItems() { 

    // Set some lat/lng coordinates to start with. 
    double lat = 51.5145160; 
    double lng = -0.1270060; 

    // Add ten cluster items in close proximity, for purposes of this example. 
    for (int i = 0; i < 10; i++) { 
     double offset = i/60d; 
     lat = lat + offset; 
     lng = lng + offset; 
     MyItem offsetItem = new MyItem(lat, lng); 
     mClusterManager.addItem(offsetItem); 
    } 
} 

欲瞭解更多信息,您可以檢查herelibrary's Github page