我正在尝试通过 MapBox Android来旋转地图以始终面向我们前进的方向。目前,这是我尝试的没有成功:
这是我初始化mapbox
地图的地方:
mapView.getMapAsync(mapboxMap -> {
Log.d(TAG, "Map is initialized");
map = mapboxMap;
map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.COMPASS);
});
这就是我启用位置的地方;
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());
}
});
}
}
mapView.getMapAsync(mapboxMap -> {
Log.d(TAG, "Map is initialized");
map = mapboxMap;
map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.TRACKING_FOLLOW);
});
答案 0 :(得分:1)
您使用的是哪个版本的SDK?上个月我merged a compass listener fix修正了罗盘轴承跟踪。您可以阅读有关issue here的更多信息。尝试更新到4.2.0-beta.3
并使用您在问题中发布的第一个代码段。如果这是您正在寻找的解决方案,请告诉我们!