What does the following code do if there is no GPS fix..?
If there is no GPS FIX (because the person is in a metal building or something)....does it just stay in the Looper..?? OR does it keep trying for a fix via requestLocationUpdates..??
If I do have a good GPS FIX....my code works fine...and in onLocationChanged()...I update the current location to the database.
Also...when is onLocationChanged() called..?? Is it only called when there is a GPS FIX..?? Just wondering..
public void run()
{
Looper.prepare();
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(Loca开发者_JAVA技巧tionManager.GPS_PROVIDER, 0, 0, ll);
Looper.loop();
}
Umm, is this in production code? Or are you just curious. This is absolutely not acceptable android code. Take a look at this for an idea on how to correctly implement a locationlistener
http://hejp.co.uk/android/android-gps-example/
when is onLocationChanged() called
Onlocationchanged is called when the parameters that you pass into the requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent)
method are met. That is, whenever minTime passes or the device moves minDistance. (Note those are just hints, not exact values)
I found out (after alot of testing) that of the GPS fails....it will through an error and crash my service. Instead of killing the app...I just restart the service and try it again.
精彩评论