Issue
I'm trying to rotate the map to always face the direction we are moving towards to with MapBox Android. Currently, this is what I tried without success:
This is where I initialize the mapbox
map:
mapView.getMapAsync(mapboxMap -> {
Log.d(TAG, "Map is initialized");
map = mapboxMap;
map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.COMPASS);
});
And this is where I enable the location;
private void enableLocation(boolean enabled) {
map.setMyLocationEnabled(enabled);
if (enabled) {
locationServices.addLocationListener(location -> {
if (location != null) {
// Move the map camera to where the user location is
if (location.getBearing() != 0) {
map.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(location))
.bearing(location.getBearing())
.build());
} else {
map.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(location))
.build());
}
Log.e(TAG, "location bearing:" + location.getBearing());
}
});
}
}
I ended up using this on the last version of MapBox:
mapView.getMapAsync(mapboxMap -> {
Log.d(TAG, "Map is initialized");
map = mapboxMap;
map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.TRACKING_FOLLOW);
});
Solution
Which version of the SDK are you using? I merged a compass listener fix last month that fixed the compass bearing tracking. You can read more about the issue here. Try updating to 4.2.0-beta.3
and use the first snippet you posted in your question. Let me know if this is the fix you were looking for!
Answered By - cammace
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.