Questions
The method which I am using right now is very unreliable.
In my Android device(not simulator) most of the times the location returned is null .Though sometimes it does work.
public Location getLocation(String provider) {
if (locationManager.isProviderEnabled(provider)) {
locationManager.requestLocationUpdates(provider,
MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);
return location;
}
}
return null;
}
I know that after the introduction of API 23 there are other permissions I need to take care of.
Is there a reliable way to get location ?
Answers
http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String)
http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String)
This can be done without starting the provider. Note that this
location could be out-of-date , for example if the device was turned
off and moved to another location.
If the provider is currently disabled, null is returned .
And last thing that i want to notice you, calling requestLocationUpdates method does not mean it will give you location asap. So this is why i mentioned you onLocationChanged callback method.
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/36522125/what-is-the-most-reliable-method-to-get-location-of-an-android-device
Related