Android requestLocationUpdates and time needed to get a gps fix - android

I am using the requestLocationUpdates method of LocationManager to get GPS location updates. I am using a minTime parameter of 60000 to indicate that I'd like a location update every minute - I don't care about minDistance (I use a value of 0 as minDistance).
If I can understand correctly the android documentation, my LocationListener will be executed every minute to receive the current location. This is what happens with the emulator.
However, I couldn't understand what would happen between executions: Will the GPS be turned off every time ? And If the GPS is turned off, what will happen with the time needed to get a GPS fix (that time could be more than one minute) ? Will I get updates every 1 minute + (time neede to get the GPS fix) ?
Unfortunately the emulator cannot help me with these problems and I do not have an Android device in my hands right now, so If anybody has experience with this stuff help me !
Thanks in advance!

It is not specified, because that is implementation-specific.

The latest GPS chipsets can usually get a lock in well under a minute, often less than 20 seconds, so you should be fine.

Related

Sometimes getting GPS location late i.e. more than one minute in android

I developed an application that fetches GPS location. I specified minTime as 20 seconds and minDistance as 1 meter in requestLocationUpdate method. But still i am getting location in 2-3 seconds interval and sometimes it takes more than one minute. Can i get location at particular time interval and within 1 minute?
Please Help.
Thanks in advance.
Can i get location at particular time interval and within 1 minute?
Not necessarily.
First, you set minDistance to 1 meter. Try using 0.
Second, you are limited by how frequently the GPS radio actually gets fixes, which will be based on environmental factors and is outside of your control.
Third, minTime is a hint, as the documentation explains. Hence, you may get fixes more frequently than it, or less frequently. For a minTime of 20 seconds, it is unlikely that Android will power down the GPS radio between fixes, and so I suspect that value is not helping you any.

Android onLocationChanged

Usually how much time has passed from begin of moving to first onLocationChanged event?
How much are delay time if it is exist, or immediately realize the GPS the begin of moving?
I believe that even the first time you get a locate, onLocationChanged will be called.
In terms of when they are getting called, I do not think there is any sort of polling involved in the default behavior (so there is no specified delay time), but you are able to change it yourself if you plan to do things whenever there is a change in location: https://sites.google.com/site/androidhowto/how-to-1/get-notified-when-location-changes
i'm just sitting on my laptop with gps enabled on my phone and onlocationchanged is polling non stop. The phone location is not accurate within 40 meters, and onlocationchanged() is giving me a latitude and longitude for 15+ decimal places, which is about 1 angstorm.

Time from location fix using emulator is off

I'm writing some android code to test out the geolocation libraries and I'm running into a problem with the android emulator. I am creating a LocationListener and when LocationListener::onLocationChanged is called I check the time of the passed in Location object to compare it to the current time. I use the DDMS emulator control window to change the location to trigger the call to onLocationChanged. Here is the code that I use in the onLocationChanged method to compare the passed in location time to the current time ("location" is the location that is passed into onLocationChanged):
float accuracy = location.getAccuracy();
long curTime = System.currentTimeMillis();
float lateness = (curTime - location.getTime()) / 1000;
The problem I'm having is that the time I get from location using getTime is always way off of the current time (curTime) even though the time between when I set the location using DDMS and the time I look at it in the debugger is a matter of seconds. Usually the difference is several hours, and sometimes the time from location is several hours ahead of the current time (so the time of the location fix occurs several hours in the future?!?). Additionally, the time diffference is not consistent. The documentation for the call to Location::getTime and System.currentTimeMillies both say that the returned time is given in milliseconds since Jan 1 1970 UTC, so it shouldn't be an issue of using different time zones. Is this a known bug with the emulator or is there something I'm doing wrong? Thanks!
GPS time is actually different from time on the device. So, they can differ by a huge amount. Wiki has a nice explanation here
More information about this can be found at Android emulator's GPS location gives wrong time as well as the bug report link. Additionally Android problem finding out how recent latest GPS fix is may be worth reading as well as to why system time and GPS time won't match.

Location services. Not getting the first fix if minTime is greater than 15 minutes

This is a very strange behaviour. If I have something like this (time interval set to 30 minutes):
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,30 * 60 * 1000,100,mLocationListener);
My first fix takes forever and sometimes I don't get it at all (I waited for about 20 minutes) However if I choose a smaller interval for the time (30 seconds) I get it right away.
I thought that the values minTime and minDistance are only for getting new consecutive updates, and it wouldn't affect the first fix. I should get the first fix as soon as it's available. Am I doing something wrong?
Thanks
I'd suggest to use two locationManagers, one as you are already doing for long-term updates, and another to get the first fix. Then you can unregister the second one as soon as you get the callback from it.
I heard of this pattern from Reto Meier and it's called "back-off" location. We are using it in mixare with the coarse location manager to get the first fix, and the GPS to get more precise infos. You can check the code here: https://github.com/mixare/mixare/blob/master/src/org/mixare/MixContext.java starting at line 150 (more or less)
HTH,
Daniele
You may check, if well-known 3rd party GPS tools (like GPS Status) have problems as well, or there is something with your code.
Please keep in mind that satellite visibility -- and therefore GPS signal quality -- may change quickly and first fix in a few days may take substantially longer than usual.

Android problem finding out how recent latest GPS fix is

My app uses LocationListener to keep track of the current location. So long as the GPS Provider is providing regular fixes this works well. However, I want my app to alert the user if the location is no longer reliable because the fix is no longer current. I have therefore used a timeCheckHandler to call getLastKnownLocation every few seconds.
My problem is that even when accurate fixes are being received frequently the time returned by applying getTime() to the location returned by getLastKnownLocation is generally older than the current time returned by System.currentTimeMillis(), often by about 20 seconds.
I have investigated the problem further by adding code to onLocationChanged(arg0) to log the time of the fix (arg0.getTime()) and the current time (System.currentTimeMillis()). Again I see a difference of about 20 seconds.
The code currently reads as follows:
public void onLocationChanged(Location arg0) {
mapview.handleLocationChanged(mapview, arg0.getLatitude(), arg0.getLongitude(), arg0.getBearing(), arg0.getAccuracy(), "GPS fix");
addDebugNote("Fix received at time: "+Long.toString(arg0.getTime()/1000)+" Now: "+Long.toString((System.currentTimeMillis())/1000));
}
and typical output to my Debug file reads:
Fix received at time: 1292091908 Now: 1292091928
Why should I be seeing this difference between the fix time and the current system time?
Do I have to accept that a difference of around 20 seconds is normal?
GPS location time comes independently of your network provider time/device time. System.currentTimeMillis() will give you device time set on your device.
If you want to know how recent the point is you can:
Synchronize both the times ( GPS and device ) in your code at application start by taking the difference between both as soon as you get first GPS location update. At that instant query device time and see what's the difference in both. Save this difference in variable.
Use this as a correction factor in subsequent location updates to know the exact time based on the reference frame you need. ( Device time or GPS)
Also I had found that using NETWORK as location provider you may get device time only. So if you are listening on updates from both ( GPS and network ) , you may also need to distinguish this using location_obj.getProvider() and filter out GPS provider.
Repeating the test today I have found that the difference between the GPS time and the System time is 22 seconds. This issue is discussed elsewhere on the web and it seems that it is normal for there to be a difference between GPS time and the phone's system time (which in my case is set to be updated automatically from the network.) One factor is that GPS time is about 15 or 17 seconds (depending on which source is correct) from UTC time ... it is out-of-sync because GPS time has not been updated since 1980 for periodic "leap seconds."
Bearing this in mind I think the answer to my need to check how current the latest fix is will be to compare the current system time with the system time (not the GPS time) of the latest fix.

Categories

Resources