我刚刚开始开发一个 android 项目,并且正在使用 Google Map API。
我可以在我的应用程序上获取 map ,但是当我尝试使用 map.setMyLocationEnabled(true);
启用当前位置时,应用程序说不幸的是应用程序已停止工作。
当我删除行 map.setMyLocationEnabled(true);
然后它工作正常。谁能帮我启用当前位置按钮。
最佳答案
如果您使用的是 android 6.0 或更高版本,您应该:
- 确保在
AndroidManifest
文件中添加了ACCESS_COARSE_LOCATION
和ACCESS_FINE_LOCATION
。 - 您需要在运行时检查此链接的权限:Requesting Permission
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality;
如果你想要一个易于使用的库来进行权限检查,我建议 Permission Dispatcher .
关于android - map.setMyLocationEnabled(true);不管用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39395739/