tags:

views:

49

answers:

1

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(LocationManager.GPS_PROVIDER, 0, 0, ll);

        Looper.loop();
    }
A: 

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)

Falmarri
Stern and informative. Good answer!
AndrewKS
This is not production code. But what is wrong with my code..?? I am running this as a service. It was complaining that I did not have a Looper in place...so this is what I did. My code appears to be working fine. I was just wondering what happened to my code when there is NO GPS fix.
Biggs
First, it looks like this code is in some sort of thread. I guess this because it's in a `run` method. `Requestlocationupdates` is asynchronous, so it doesn't need to be in a thread. That's probably what your error about looper is. Your code MIGHT work, but you can get a lot of very poorly written code to work. Getting your code to compile and run shouldn't be a measure of success.
Falmarri
What's with the -1?
Falmarri