根据 phone 当前方向旋转 Mapbox 地图
Rotate Mapbox Map depending of the phone current orientation
我正在尝试旋转地图以始终面向我们使用 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());
}
});
}
}
我最终在最新版本的 MapBox 上使用了它:
mapView.getMapAsync(mapboxMap -> {
Log.d(TAG, "Map is initialized");
map = mapboxMap;
map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.TRACKING_FOLLOW);
});
您使用的是哪个版本的 SDK?我merged a compass listener fix last month that fixed the compass bearing tracking. You can read more about the issue here。尝试更新到 4.2.0-beta.3
并使用您在问题中发布的第一个片段。让我知道这是否是您正在寻找的修复方法!
我正在尝试旋转地图以始终面向我们使用 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());
}
});
}
}
我最终在最新版本的 MapBox 上使用了它:
mapView.getMapAsync(mapboxMap -> {
Log.d(TAG, "Map is initialized");
map = mapboxMap;
map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.TRACKING_FOLLOW);
});
您使用的是哪个版本的 SDK?我merged a compass listener fix last month that fixed the compass bearing tracking. You can read more about the issue here。尝试更新到 4.2.0-beta.3
并使用您在问题中发布的第一个片段。让我知道这是否是您正在寻找的修复方法!