Created
September 10, 2013 10:54
-
-
Save tagrudev/6507811 to your computer and use it in GitHub Desktop.
Locations Locations
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
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 | |
} | |
} |
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
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