简体   繁体   中英

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. 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. 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. Permission for ACCESS_COARSE_LOCATION allows access only to NETWORK_PROVIDER.

Read more at https://developer.android.com/guide/topics/location/strategies.html#Permission

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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