Possible Duplicate:
get current location in android
I’m trying to make an application for android that gives me the position of the device.
I’m using the LocationManager.requestlocationupdates method to start a listener.
Unfortunately this doesn’t work. When I’m looking for the stacktrace in Logcat I don’t find any error but one sentence.
11-28 12:01:17.377: E/AndroidRuntime(1138): at
Tom.Tracer.App.GetCoords.run(GetCoords.java:28)
This line doesn’t really help me further..
I’m using this code :
@Override
public void run() {
lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE) ;
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener) ;
}
The Listener
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Date date = new Date();
toSave = "NEW" + date.toString()+ "-" + location.getLatitude() + "-" + location.getLongitude() + "/";
p("To save: " + toSave);
}
};
Thanks for your help!
I forgot to call the Looper.prepare() method .
Thanks for your comments!