Below implementation creates a locationlistener that records the updated values as strings for convenience which can be easily extracted. By using the LocationManager you abstract the underlying method (GPS/assissted-GPS, wifi, cell-tower) to retrieve the location.
Initialize first:
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final myLocationListner ll = new myLocationListner();
LocationListener:
public class myLocationListner implements LocationListener {
public static String lattitude = "";
public static String longitude = "";
@Override
public void onLocationChanged(Location loc) {
String temp_lattitude = String.valueOf(loc.getLatitude());
String temp_longitude = String.valueOf(loc.getLongitude());
if(!("").equals(temp_lattitude))lattitude = temp_lattitude;
if(!("").equals(temp_longitude))longitude = temp_longitude;
}
@Override
public void onProviderDisabled(String arg0) {
}
@Override
public void onProviderEnabled(String arg0) {
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
}