Biggs
Biggs

Reputation: 141

What does this line of code do..?

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1200000, 200, ll);

My assumption is that it gets the location every 120000ms if it has changed more then 200 meters.

At least this is what I am experiencing anyway....which is what I want. But what happens if the phone ends up in a metal building where there is NO GPS reception..??

Does it just keep trying every 1200000ms for a GPS fix forever..?? Or does this eventually die off and not work again..??

If I put the phone on my dash and drive around...every 120000ms I send a SMS message with the latest coordinates. Everything works just fine. But if the phones ends up in a building for 3-4-5 hours and comes back out side 3-4-5 hours later....my hope is that it will pick back up where it left off and send me a new location (if it has changed more than 200 meters). But this does not appear to be the case. It just stops working and I never get a new location even if I do have a clear view of the sky. Just wondering if this stops searching for a GPS fix or something after so many attempts to obtain a GPS fix...?

Upvotes: 0

Views: 180

Answers (2)

Octavian Helm
Octavian Helm

Reputation: 39604

It sounds like you are searching for the Critera class.

You basically define a set of criteria which then is used to get the best suitable provider for this criteria. You then pass this criteria to the getProviders() method of the LocationManager class to get the best suitable provider as a string. Be it GPS, Network etc.

You can alternatively specify the fix provider manually by doing something like this

// Get a fix from the GPS provider
LocationProvider provider = LocationManager.GPS_PROVIDER;

// Get a fix from the Network provider
LocationProvider provider = LocationManager.NETWORK_PROVIDER;

There is a very interesting read on the developers site about obtaining users location you might want to check out. Especially the part about deciding when to start listening might be of interest for you but I recommend reading the whole article.

Using the Network provider will get your best possible position without a GPS fix in other words also inside a building. You have to keep in mind tho that the position fix you obtain might be quite off of the real position when querying the network provider.

The method you are asking for requestLocationUpdates(String provider, long minTime, long minDistance, LocationListener listener) will request a location update from the set provider every minTime milliseconds or every minDistance meters and inform the listener upon that.

Hope it helps.

Upvotes: 1

Wim ten Brink
Wim ten Brink

Reputation: 26682

Did you check this site? Specifically this link: http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String, long, float, android.app.PendingIntent)

void requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent) Registers the current activity to be notified periodically by the named provider.
void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) Registers the current activity to be notified periodically by the named provider.
void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener, Looper looper) Registers the current activity to be notified periodically by the named provider.
But the call you're showing uses an int as last parameter. That's not a documented function.

Upvotes: 0

Related Questions