我正在使用Map Utils库在地图上进行聚类。现在,我想要更改默认标记,它们在地图中显示如下:
你可以在绿色圆圈中看到标记。我想改变它。我已经实现了这个。但不知道如何改变这一点。如果你们有人知道然后帮助解决这个问题。
代码:
@Override
protected void startDemo() {
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10));
mClusterManager = new ClusterManager<MyItem>(this, getMap());
getMap().setOnCameraChangeListener(mClusterManager);
try {
readItems();
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
}
}
private void readItems() throws JSONException {
InputStream inputStream = getResources().openRawResource(R.raw.radar_search);
List<MyItem> items = new MyItemReader().read(inputStream);
mClusterManager.addItems(items);
}
答案 0 :(得分:6)
您应该实现onBeforeClusterItemRendered
并通过制作自定义Renderer类进行更改:
public class MarkerClusterRenderer extends DefaultClusterRenderer<MyItem> {
public MarkerClusterRenderer(Context context, GoogleMap map,
ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
@Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
// use this to make your change to the marker option
// for the marker before it gets render on the map
markerOptions.icon(BitmapDescriptorFactory.
fromResource(R.drawable.your_custom_marker));
}
}
并且不要忘记将自定义渲染器添加到Cluster Manager
mClusterManager.setRenderer(new MarkerClusterRenderer(this, mMap, mClusterManager));
答案 1 :(得分:-2)
您可以使用此片段创建自定义标记。
Marker marker = googleMap.addMarker(new MarkerOptions().
position(51.503186, -0.126446).title("mapTitle").snippet("is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));