如何解决空对象引用上的LocationComponent com.mapbox.mapboxsdk.maps.MapboxMap.getLocationComponent'
嘿,我正在做一个mapbox超级应用程序。过去,骑手和驾驶员应用程序正常工作,但是在过去的几天里,我在LocationCompoment上遇到了空错误..你们能帮助我了解发生了什么吗? 这是代码:
private void enableLocationComponent(@NonNull Style loadedMapStyle) {
// Check if permissions are enabled and if not request
if (PermissionsManager.areLocationPermissionsGranted(this)) {
// Get an instance of the component
LocationComponent locationComponent = mapboxMap.getLocationComponent();
if (locationComponent != null){
// Activate with options
locationComponent.activateLocationComponent(
LocationComponentActivationOptions.builder(this,loadedMapStyle).build());
// Enable to make component visible
locationComponent.setLocationComponentEnabled(true);
// Set the component's camera mode
locationComponent.setCameraMode(CameraMode.TRACKING);
// Set the component's render mode
locationComponent.setRenderMode(RenderMode.COMPASS);
} } else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
解决方法
为什么要进行两次if (PermissionsManager.areLocationPermissionsGranted(this))
检查?您只需要一个。
设置项目以匹配https://docs.mapbox.com/android/maps/examples/show-a-users-location/,这是显示设备位置的最基本方法。
您还可以在LocationComponent locationComponent = mapboxMap.getLocationComponent();
之后进行空检查
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。