map.setMyLocationEnabled(真);不管用 [英] map.setMyLocationEnabled(true); is not working

查看:574
本文介绍了map.setMyLocationEnabled(真);不管用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始致力于一个Android项目,并且正在使用Google Map API。



我可以在我的应用上获取地图,但是当我尝试使用 map.setMyLocationEnabled(true)启用当前位置时, code>,该应用程序说,不幸的是应用程序已停止工作。

当我删除 map.setMyLocationEnabled(true); 行时,它工作正常。任何人都可以帮助我获取当前位置按钮。

解决方案

如果您使用的是Android 6.0或更高版本,您应该:


  1. 确保您添加了 ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION 在您的 AndroidManifest 文件中。

  2. 您需要在此链接的运行时检查权限:请求权限

  3. $ 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:

    1. Make sure you added ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION in your AndroidManifest file.
    2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆