Skip to content

Instantly share code, notes, and snippets.

@walteranyika
Created November 17, 2015 10:49
Show Gist options
  • Save walteranyika/6108966f0dfcef4d6d53 to your computer and use it in GitHub Desktop.
Save walteranyika/6108966f0dfcef4d6d53 to your computer and use it in GitHub Desktop.
Code To Get Location Updates For An App
try
{
LocationListener listener=new LocationListener() {
@Override
public void onLocationChanged(Location location) {
double lat= location.getLatitude();
double lon = location.getLongitude();
double speed =location.getSpeed();
//do something with this values
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("DATA","STATUS CHANGED "+provider);
}
@Override
public void onProviderEnabled(String provider) {
Log.d("DATA","PROVIDER ENABLED "+provider);
}
@Override
public void onProviderDisabled(String provider) {
Log.d("DATA","PROVIDER DISENABLED "+provider);
}
};
String provider=LocationManager.GPS_PROVIDER;
manager.requestLocationUpdates(provider,5000,5,listener);
}catch (SecurityException e)
{
Log.e("DATA","Could Not Fetch The Location");
}
//manager.removeUpdates();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment