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 ?