Skip to content

Instantly share code, notes, and snippets.

@onlyangel
Created December 9, 2011 21:11
Show Gist options
  • Save onlyangel/1453311 to your computer and use it in GitHub Desktop.
Save onlyangel/1453311 to your computer and use it in GitHub Desktop.
// AndroidManifest.xml must have the following permission:
// <uses-permission
// android:name="android.permission.ACCESS_FINE_LOCATION"/>
LocationManager locationManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new LocationListener() {
public void onStatusChanged(String provider, int status,
Bundle extras) {
// called when the provider status changes. Possible
// status: OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or
// AVAILABLE.
}
public void onProviderEnabled(String provider) {
// called when the provider is enabled by the user
}
public void onProviderDisabled(String provider) {
// called when the provider is disabled by the user, if
// it's already disabled, it's called immediately after
// requestLocationUpdates
}
public void onLocationChanged(Location location) {
double latitute = location.getLatitude();
double longitude = location.getLongitude();
// do whatever you want with the coordinates
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment