我正在使用Mapbox的更新的SDK。但是我无法将marker添加到当前位置。此外,我没有当前位置的纬度和经度。我只是使用locationComponent来显示当前位置。如果有人举起您的援助之手,这将非常有帮助。.[[提前感谢。
如果这太复杂,或者您不需要不断跟踪位置,则在设置Location lastKnownLocation = mapboxMap.getLocationComponent().getLastKnownLocation();
(LocationComponent
)后就可以进行https://docs.mapbox.com/android/maps/examples/show-a-users-location/。
Location lastKnownLocation = mapboxMap.getLocationComponent().getLastKnownLocation();
lastKnownLocation.getLatitude();
lastKnownLocation.getLongitude();
现在有了坐标,您可以添加SymbolLayer
或将新坐标添加到现有SymbolLayer
的GeoJSON。https://docs.mapbox.com/android/maps/examples/marker-symbol-layer/
如何更新
SymbolLayer
GeoJSON以便出现新标记:
map.getStyle(new Style.OnStyleLoaded() { @Override public void onStyleLoaded(@NonNull Style style) { featureList.add(Feature.fromGeometry(Point.fromLngLat(lastKnownLocation.getLongitude(), lastKnownLocation.getLatitude()))); FeatureCollection newFeatureCollection = FeatureCollection.fromFeatures(featureList); GeoJsonSource source = style.getSourceAs("symbol-layer-source-id"); if (source != null) { source.setGeoJson(newFeatureCollection); } } });