如何使用此方法对标记进行聚类?我想用当前的方法将标记分组。
EasyDB stores = EasyDB.init(getActivity(), "Objects");
stores.setTableName("Stores");
Cursor res = stores.getAllData();
while (res.moveToNext()) {
String name = res.getString(5);
String lat = res.getString(8);
String lang = res.getString(9);
String desc = res.getString(4);
mapboxMap.addMarker(new MarkerOptions()
.setIcon(icon)
.position(point)
.setSnippet(snipp)
.title(id));
}
发布于 2020-04-30 01:52:24
考虑到这里使用的是MarkerOptions
,看起来您使用的是Mapbox Annotations plugin for Android。如果是这样,您将需要从数据库中的标记创建一个GeoJSON object,以便可以使用GeoJsonOptions
对象传递给SymbolManager
实例以启用集群。例如,如果您将数据解析为GeoJSON对象并将其存储在变量geoJsonData
中
GeoJsonOptions geoJsonOptions = new GeoJsonOptions()
.withCluster(true)
.withClusterMaxZoom(14)
.withClusterRadius(10);
symbolManager = new SymbolManager(mapView, mapboxMap, style, null, geoJsonOptions);
symbolManager.setIconAllowOverlap(true);
List<SymbolOptions> options = new ArrayList<>();
for (int i = 0; i < geoJsonData.length(); i++) {
Feature feature = features.get(i);
options.add(new SymbolOptions()
.withGeometry((Point) feature.geometry())
.withIconImage("name-of-icon-to-use-for-clusters")
);
}
Mapbox Android Plugins demo app中的This example展示了如何使用注释实现集群。
https://stackoverflow.com/questions/61457032
复制相似问题