Я использую последнюю библиотеку MapBox (0.22.0) . Я пытаюсь повернуть карту, чтобы она всегда смотрела в направлении, к которому мы движемся, с помощью MapBox Android .
Это мой код:
@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxmap = mapboxMap;
mapboxMap.setStyle(Style.OUTDOORS);
mapboxMap.getUiSettings().setAttributionEnabled(false);
mapboxMap.getUiSettings().setCompassEnabled(true);
mapboxMap.getUiSettings().setLogoEnabled(false);
mapboxMap.getUiSettings().setRotateGesturesEnabled(true);
mapboxMap.getUiSettings().setZoomControlsEnabled(true);
initLocationEngine();
initLocationLayer();
}
private void initLocationLayer() {
/* LocationLayerPlugin locationLayer = new LocationLayerPlugin(mapView, mapboxmap, locationEngine);
locationLayer.setRenderMode(RenderMode.GPS);*///(Old Lib Code 0.19.0)
LocationComponent locationComponent = mapboxmap.getLocationComponent();
locationComponent.activateLocationComponent(getActivity(), locationEngine);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setCameraMode(CameraMode.TRACKING);
locationComponent.setRenderMode(RenderMode.COMPASS);
locationComponent.zoomWhileTracking(30);
}
@SuppressLint("MissingPermission")
private void initLocationEngine() {
locationEngine = new LocationEngineProvider(activity).obtainBestLocationEngineAvailable();
locationEngine.setPriority(HIGH_ACCURACY);
locationEngine.setInterval(0);
locationEngine.setFastestInterval(1000);
locationEngine.addLocationEngineListener(this);
//userTrackingMode
locationEngine.activate();
if (locationEngine.getLastLocation() != null) {
Location lastLocation = locationEngine.getLastLocation();
onLocationChanged(lastLocation);
currentLocation = Point.fromLngLat(lastLocation.getLongitude(), lastLocation.getLatitude());
}
}