Skip to content

Instantly share code, notes, and snippets.

@tagrudev
Created September 10, 2013 10:54
Show Gist options
  • Save tagrudev/6507811 to your computer and use it in GitHub Desktop.
Save tagrudev/6507811 to your computer and use it in GitHub Desktop.
Locations Locations
public class CurrentLocationListener implements LocationListener{
public static double latitude;
public static double longitude;
@SuppressWarnings("static-access")
@Override
public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude();
this.latitude=location.getLatitude();
this.longitude=location.getLongitude();
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
OnCreate
-> locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
#Then on the menu
In onOptionsItemSelected
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, true);
this.location = locationManager.getLastKnownLocation(provider);
if (location != null) {
CurrentLocationListener crLocation = new CurrentLocationListener();
crLocation.onLocationChanged(location);
Log.i("Location", String.valueOf(location.getLatitude()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment