tags:

views:

72

answers:

2
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...?

A: 

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.

Workshop Alex
Yes..I have been there and everywhere else several times. This does not explain the behavior that I am experiencing. I am looking for a more simplistic answer. Android's definition is too complicated to understand.
Biggs
Biggs, my best understanding is that when it loses gps, it will stop trying to reconfigure every so many ms, because it dont think it's moved. Although this understanding might be wrong.. My best guess would be to just try it out, I dont think You're going to have a problem with it
Samuel
My last parameter is "ll" which stands for location listener. It is not an int.
Biggs
Samuel... I think you might be right. It will try and after so many attempts it will just stop trying and not try again at all. This is what I am seeing. If I am driving a car everything works fine. But as soon as I go into a building...I do not get any more updates (which is expected)....but when I go out side and get back in the car..I expect it to start working again...but it doesn't. So I think after it craps out several times with no luck of getting a GPS fix.... it just gives up. The reason I say this is because I never ever get any more new updates even though I have clear LOS to GPS.
Biggs
If the last parameter isn't an int but a location listener then you're using the middle method from my list. Still, it's not uncommon from libraries doing things differently from the documentation. You would need to read the code behind this method to understand what it's doing exactly.
Workshop Alex
+1  A: 

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.

Octavian Damiean
I am fine with just setting the provider to GPS. I do not need GPS while in a building. I am just wondering why it quits trying to get GPS when in a building and come back out side 2-3-4 hours later. Shouldn't it pick up where it left off..?? The main question at hand is......Does it quit trying to obtain GPS fix after it gets rejected several times..??
Biggs
I'm not quite sure but I imagine you have to handle this yourself in the LocationListener. You have a method called onStatusChanged() which handles events of reachability loss of a location provider or regained reachability of the provider. Here is a link to the reference of the method I'm talking about. http://developer.android.com/reference/android/location/LocationListener.html#onStatusChanged(java.lang.String, int, android.os.Bundle)
Octavian Damiean
Octavian Damiean.... I think you are correct. In the onStatusChange method you must be able to handle the fact that there is NO GPS signal. Do you have any suggestions..?? I was thinking that maybe since there is NO gps signal that maybe just sit there and wait until it is available again..?? A busy loop is probably not good...but this method does not appear to be called any more so it kind of seams that we have to keep this method alive or something.
Biggs