Created
August 4, 2018 06:09
-
-
Save 100rabhkr/7c9590292d752418776c3e608d09ff0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LocationManager mLocationManager; | |
Location myLocation = getLastKnownLocation(); | |
private Location getLastKnownLocation() { | |
mLocationManager = (LocationManager)getApplicationContext().getSystemService(LOCATION_SERVICE); | |
List<String> providers = mLocationManager.getProviders(true); | |
Location bestLocation = null; | |
for (String provider : providers) { | |
Location l = mLocationManager.getLastKnownLocation(provider); | |
if (l == null) { | |
continue; | |
} | |
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) { | |
// Found best last known location: %s", l); | |
bestLocation = l; | |
} | |
} | |
return bestLocation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment