您拥有的最佳方式是使用群集管理器将项目添加到地图。
您创建了一个实现ClusterItem并创建自己的项目的类。 你需要有一个功能选择图标类型命名setIconByData:您需要在活动或片段类的功能来组织项目
public class MyItem implements ClusterItem {
private final LatLng mPosition;
private MarkerOptions markerOptions;
private String data;
private int iconReference;
public MyItem(double lat, double lng) {
mPosition = new LatLng(lat, lng);
}
public MyItem(MarkerOptions markerOptions) {
this.setMarkerOptions(markerOptions);
mPosition = markerOptions.getPosition();
}
public MyItem(LatLng latLong) {
mPosition = latLong;
}
@Override
public LatLng getPosition() {
return mPosition;
}
public MarkerOptions getMarkerOptions() {
return markerOptions;
}
public void setMarkerOptions(MarkerOptions markerOptions) {
this.markerOptions = markerOptions;
}
public int getIconReference() {
return iconReference;
}
public void setIconReference(int iconReference) {
this.iconReference = iconReference;
}
public void setIconByData(String data, MyItem myItem) {
if(data.equals("museum"))
myItem.setIconReference(iconMuseum);
else
myItem.setIconReference(iconGolf);
}
}
的。 此功能需要返回项目的集合:
private Collection<MyItem> organizeItems(LatLng latlong) {
Collection<MyItem> res = new ArrayList<MyItem>();
MarkerOptions markerOptions = new MarkerOptions().position(latlong);
MyItem item = new MyItem(markerOptions);
item.setIconByValencia("golf", item);
res.add(item);
return res;
}
然后,当你想你清理经理和添加新项目:
mClusterManager = new ClusterManager<MyItem>(v.getContext(), map); //on create
//when you want to refresh the items:
mClusterManager.clearItems();
mClusterManager.addItems(addItems(BOUNDS, TicketTypeProduct.TO));
mClusterManager.cluster();
这里你可以看到使用群集的细节和集群管理器: https://developers.google.com/maps/documentation/android/utility/marker-clustering?hl=en-EN
你面对什么问题? – duggu
分类标记。例如将其分类为商场,餐馆,加油站 – user3340295
意味着您想要在不同的2类别上显示不同的2标记? – duggu