简体   繁体   English

Android仅检测模拟位置?

[英]Android detects only mock locations?

I am making an app in which I want to get the users' location to show on a map. 我正在制作一个想要在地图上显示用户位置的应用程序。 When I am running the app on a real device, it does not seem to get this location, but it gets locations if I put in mock locations using a GPS location faker. 当我在真实设备上运行该应用程序时,它似乎无法获得此位置,但是如果我使用GPS位置伪造者将其放置在模拟位置中,它将获得位置。 In the emulator these mock locations are also detected. 在模拟器中,还会检测到这些模拟位置。

How can I get my phone to get the real location too? 我也该如何获取手机的真实位置?

Requesting User Permissions In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request the user's permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file. 请求用户权限为了从NETWORK_PROVIDER或GPS_PROVIDER接收位置更新,您必须通过在Android清单文件中分别声明ACCESS_COARSE_LOCATION或ACCESS_FINE_LOCATION权限来请求用户的权限。 Without these permissions, your application will fail at runtime when requesting location updates. 没有这些权限,您的应用程序在请求位置更新时将在运行时失败。

If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. 如果同时使用NETWORK_PROVIDER和GPS_PROVIDER,则只需要请求ACCESS_FINE_LOCATION权限,因为它同时包含两个提供程序的权限。 Permission for ACCESS_COARSE_LOCATION allows access only to NETWORK_PROVIDER. ACCESS_COARSE_LOCATION的权限仅允许访问NETWORK_PROVIDER。

Read more at https://developer.android.com/guide/topics/location/strategies.html#Permission 请访问https://developer.android.com/guide/topics/location/strategies.html#Permission了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM