I am using LocationClient method to retrieve user's current location. It is working quite well, but sometimes it is not accurate for obvious reasons like (I am being inside , using WIFI etc). I would like to know if there is a determine what Location Provider is used to fetch the location. getProvider() returns "fused" regardless if I am in inside or outside. I just need to tell user that he is not getting accurate location probably because he is in inside. Even better, tell the user what Provider is used to fetch his location.
Determining the provider of Location - Android
69 views Asked by programmerboy At
2
There are 2 answers
1
On
Check below code for getting the list of location provider -
List<String> matchingProviders = locationManager.getAllProviders();
for (String provider: matchingProviders) {
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
float accuracy = location.getAccuracy();
long time = location.getTime();
if ((time > minTime && accuracy < bestAccuracy)) {
bestResult = location;
bestAccuracy = accuracy;
bestTime = time;
}
else if (time < minTime &&
bestAccuracy == Float.MAX_VALUE && time > bestTime){
bestResult = location;
bestTime = time;
}
}
}
Hope this helps you.
You can check if provider is available using isProviderEnabled method: