2015-04-17 27 views
0

如果不使用ClusterManager,我使用HashMap將標記和ID放入HashMap中,並在OnMarkClick方法中獲取ID並從數據庫獲取數據。它的作品如何在使用ClusterManager時獲取每個Marker對象ID

markers.put(addNewMarker(geoPoint), objectId); 

private Marker addNewMarker(ParseGeoPoint parseGeoPoint) { 
    double latitude = parseGeoPoint.getLatitude(); 
    double longitude = parseGeoPoint.getLongitude(); 
    return googleMap.addMarker(new MarkerOptions().position(
      new LatLng(latitude, longitude))); 
} 

@Override 
public boolean onMarkerClick(Marker marker) { 
    String objectId = markers.get(marker); 
    if (null == objectId) { 
     return false; 
    } 
    getMemoryBriefInfo(objectId); 
    return true; 
} 

但現在我需要使用ClusterManager羣集多個標記成數。

問題是Google似乎沒有辦法實現這個,在Google的demo中,它只是將Items添加到Cluster中。

ClusterManager類中有OnMarkerClick方法,但我不知道如何覆蓋這個並使用我自己的唯一ID進行設置。

回答

-1

有一個全球性的解決方案,幫助您添加標題,代碼段和圖標,以便您可以得到您想要的。

修改您的ClusterItem對象,並添加3個變量:

public class MyItem implements ClusterItem { 

private final LatLng mPosition; 
BitmapDescriptor icon; 
String title; 
String snippet; 

public MyItem(BitmapDescriptor ic,Double lat , Double lng,String tit ,String sni) 
{ 
    mPosition = new LatLng(lat,lng); 
    icon = ic; 
    title = tit; 
    snippet = sni; 

} 

你創建你的服裝後,呈現:

public class OwnRendring extends DefaultClusterRenderer<MyItem> { 

    public OwnRendring(Context context, GoogleMap map, 
          ClusterManager<MyItem> clusterManager) { 
     super(context, map, clusterManager); 
    } 


    protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) { 

     markerOptions.icon(item.getIcon()); 
     markerOptions.snippet(item.getSnippet()); 
     markerOptions.title(item.getTitle()); 
     super.onBeforeClusterItemRendered(item, markerOptions); 
    } 
} 

之後只是把這個線你SetUpCluster()函數爲addItems之前( ):

mClusterManager.setRenderer(new OwnRendring(getApplicationContext(),mMap,mClusterManager)); 
相關問題