Android – how to get the user’s location only once without tracking?
•
Android
In my android app, I need to gt the user's location when I click the button. However, I don't need to receive continuous updates about its location
I searched for a few questions on stack overflow, but the answer is 2 – 3 years, so I want to know, like the Android SDK now, what is the best way
Also, if possible, I don't want to get null at that location
Thank you in advance
resolvent:
I know this question is very old, but in case someone needs to know the answer, you can use the setnumupdates method and pass the value 1. Example:
mLocationRequest = new LocationRequest();
mLocationRequest.setNumUpdates(1);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setNumUpdates (int)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码