map.setMyLocationEnabled(真);不管用 [英] map.setMyLocationEnabled(true); is not working
问题描述
我刚刚开始致力于一个Android项目,并且正在使用Google Map API。
我可以在我的应用上获取地图,但是当我尝试使用 当我删除 如果您使用的是Android 6.0或更高版本,您应该: map.setMyLocationEnabled(true)启用当前位置时, code>,该应用程序说,不幸的是应用程序已停止工作。
map.setMyLocationEnabled(true);
行时,它工作正常。任何人都可以帮助我获取当前位置按钮。
ACCESS_COARSE_LOCATION
和 ACCESS_FINE_LOCATION
在您的 AndroidManifest
文件中。
$ b
从Android 6.0开始(API级别23)用户在应用程序运行时向应用程序授予权限,而不是在安装应用程序时授予权限。此方法简化了应用程序安装过程,因为用户在安装或更新应用程序时无需授予权限。它还为用户提供了对应用程序功能的更多控制;
如果您想要一个易于使用的库进行权限检查,建议许可调度员。
I have just started working on a android project and is using the Google Map API.
I am able to fetch the map on my app but when i try to enable the current location with map.setMyLocationEnabled(true);
, the app says unfortunately app has stopped working.
When I removed the line map.setMyLocationEnabled(true);
then it worked fine. Can anyone please help me to get the current location button enabled.
If you are using android 6.0 or above, you should:
- Make sure you added
ACCESS_COARSE_LOCATION
andACCESS_FINE_LOCATION
in yourAndroidManifest
file. - You need to check permission at run-time in this link: 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;
If you want an easy-to-use library for permission checking, I suggest Permission Dispatcher.
这篇关于map.setMyLocationEnabled(真);不管用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!