我如何用这种方法对标记进行聚类? 我想用当前方法将标记分组。
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));
}
最佳答案
鉴于此处使用了 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")
);
}
This example来自Mapbox Android Plugins demo app展示如何使用注释实现聚类。
关于java - 没有 GeoJSON 文件的 Mapbox 聚类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61457032/