我将mapbox用于android(java),当它尝试访问设备位置时,出现错误并关闭了应用程序。当我尝试通过模拟使用该应用程序时,不会发生此问题。
此代码似乎无效。
private void enableLocationComponent(@NonNull Style loadedMapStyle) {
if (PermissionsManager.areLocationPermissionsGranted(this)) {
locationComponent = mapboxMap.getLocationComponent();
LocationComponentActivationOptions locationComponentActivationOptions =
LocationComponentActivationOptions.builder(this, loadedMapStyle)
.useDefaultLocationEngine(false)
.build();
locationComponent.activateLocationComponent(locationComponentActivationOptions);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setCameraMode(CameraMode.TRACKING);
locationComponent.setRenderMode(RenderMode.COMPASS);
initLocationEngine();
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
答案 0 :(得分:0)
logcat中的崩溃消息是什么?
您是否将完全加载的地图样式传递给enableLocationComponent()
?
您可能已经看过它们,但是对https://docs.mapbox.com/help/tutorials/android-location-listening/和https://docs.mapbox.com/android/maps/examples/#device-location