如何从已知标记(符号层)设置目的地点以从当前位置导航

时间:2019-04-04 07:30:10

标签: android mapbox mapbox-android mapbox-marker

我在addDestinationIconSymbolLayer()中添加了两个目标标记。 onMapClick(@NonNull LatLng point)函数我要将目标标记设置为制作路线的目标点。

private void addDestinationIconSymbolLayer(@NonNull Style style){
markerCoordinates.add(Feature.fromGeometry(
                            Point.fromLngLat(75.858,22.727)));
markerCoordinates.add(Feature.fromGeometry(
                            Point.fromLngLat(75.848,22.717)));
style.addSource(new GeoJsonSource("marker-source",
                            FeatureCollection.fromFeatures(markerCoordinates)));
style.addImage("my-marker-image", BitmapFactory.decodeResource(
                            MainActivity.this.getResources(), R.drawable.mapbox_marker_icon_default));
style.addLayer(new SymbolLayer("marker-layer", "marker-source")
                            .withProperties(PropertyFactory.iconImage("my-marker-image")));
}

public boolean onMapClick(@NonNull LatLng point) {
Point destinationPoint = Point.fromJson("marker-layer");
Point originPoint = Point.fromLngLat(locationComponent.getLastKnownLocation().getLongitude(),
            locationComponent.getLastKnownLocation().getLatitude());

GeoJsonSource source = mapboxMap.getStyle().getSourceAs("marker-source");
if (source != null) {
source.setGeoJson(Feature.fromGeometry(destinationPoint));
}
getRoute(originPoint, destinationPoint);
button.setEnabled(true);
button.setBackgroundResource(R.color.mapboxBlue);
return true;
}

我想按我在addDestinationIconSymbolLayer()中设置的标记,从自己的位置获取路线。

0 个答案:

没有答案