[android-developers] Re: Age of GPS data (continued)
Can you check to see if your user has selected Automatic - Use network-provided values? The second question would be: Where does the location.getTime() time come from? Is it provided by the satellite fix itself or from the phone. If from the phone then it's not really relevant how the user sets the time. I'm curious as to the cause and effect of system time on GPS time. I hadn't considered it before reading this question but my app is also dependent on the comparing the fix time vs. the clock time. -John Coryat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Age of GPS data (continued)
try usin the time tick event instead of systime... u cud keep track of the time ticks elapsed... since u said couple of minutes: I'm trying to check the age of a GPS fix, so that I can discard location fixes that are more than, say, a couple of minutes old - I need my fix to be very accurate. have a look at this: http://developer.android.com/reference/android/content/Intent.html#ACTION_TIME_TICK this is jus a round abt method... hope it helps. cheers! On Tue, Jul 21, 2009 at 3:52 PM, Anna PS annapowellsm...@googlemail.comwrote: Hi all Just updating this thread, which seems to be too old for me to post a follow-up: http://groups.google.com/group/android-developers/browse_thread/thread/df1e14fe4e9ad896/ I'm trying to check the age of a GPS fix, so that I can discard location fixes that are more than, say, a couple of minutes old - I need my fix to be very accurate. This is the code I use: long locationTime = location.getTime(); long currentTime = System.currentTimeMillis (); timeDifference = (currentTime - locationTime) / 1000; if (timeDifference 120) { // warn the user } However, this method is entirely dependent on the user having set their system time correctly. If they are just a few minutes out (and lots of people do like to keep their clocks a few minutes fast) then they will only ever get warned. I don't know what to do - I can't accept location data that's potentially out of date, nor can I rely on my users to have correct system time within a couple of minutes. The problem is that there is no way to check the age of the GPS data itself, just the time (location.getTime() returns the UTC time, rather than the the age, of the data). Is there any way around this? I guess I could check the locationTime a few times in succession and see if it changes, and assume that if it changes then it must be getting updated, but it feels kind of fiddly. Thanks Anna --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Age of GPS data (continued)
I just did a test. location.getTime() 1248184334000 System.currentTimeMillis() 1248184346934 It appears as if the GPS tracks time down to the second and it can vary from the Automatic setting by quite a bit. This example shows a variance of about 100 seconds between the two. Perhaps the best strategy would be to save a time difference as a setting for the app, while updating this value every time a difference is noted. -John Coryat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Age of GPS data (continued)
Hi John Yes, that's exactly what I have done - I've saved the time of the first fix, and compare it to the time of the latest fix. If the two are the same when the time comes to check location, i.e. there is no time difference, I know that there hasn't been an update during the life of the application, and so the fix is probably out of date. Thanks, Anna On Jul 21, 4:29 pm, Maps.Huge.Info (Maps API Guru) cor...@gmail.com wrote: I just did a test. location.getTime() 1248184334000 System.currentTimeMillis() 1248184346934 It appears as if the GPS tracks time down to the second and it can vary from the Automatic setting by quite a bit. This example shows a variance of about 100 seconds between the two. Perhaps the best strategy would be to save a time difference as a setting for the app, while updating this value every time a difference is noted. -John Coryat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Age of GPS data
Thanks. Yes, it works much better with requestLocationUpdates set to 0. For the benefit of anyone reading and reusing code, requesting location updates drains the battery very quickly, so remember to unregister the LocationListener whenever you pause the application. Code below. Anna @Override public void onPause() { Log.d(LOG_TAG, onPause); // Unregister the LocationListener locationmanager.removeUpdates(listener); super.onPause(); } On Feb 4, 8:52 pm, Ludwig ludwigbrinckm...@gmail.com wrote: The Location object has a getTime() method that should supply you with the age of the fix. The getLastKnownLocation() call does not miraculously have another source of location information than what you would get with the upcall. Set the time in requestLocationUpdates to 0 to get notifications as frequently as possible: that way you have the most up-to-date location your device can give you. Ludwig 2009/2/4 Anna PS annapowellsm...@googlemail.com Hi Ludwig, Thanks for the suggestion. I do implement a listener, when the application opens. But I found that the GPS data using getLastKnownLocation was often out of date or inaccurate, and that caused me real problems, since it's a mapping application and the data needs to be very accurate - I need to warn the user if it isn't. Hence the polling to make sure it's up to date. (I run the polling in a background thread.) I've pasted my listener code below, that I call from onCreate... do you suggest any changes? thanks, Anna //This function called from onCreate... public boolean testProviders() { Log.d(LOG_TAG, testProviders); String location_context = Context.LOCATION_SERVICE; locationmanager = (LocationManager) getSystemService (location_context); listener = new LocationListener() { public void onLocationChanged(Location location) { } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }; locationmanager.requestLocationUpdates(gps, 500, 0, listener); Log.d(LOG_TAG, Checking location with provider + gps); location = locationmanager.getLastKnownLocation(gps); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); latString = latitude.toString(); longString = longitude.toString(); Log.d(LOG_TAG, Location found: latitude + latString + and longitude + longString); return true; } else { Log.d(LOG_TAG, Location not found); return false; } On 2 Feb, 12:50, Ludwig ludwigbrinckm...@gmail.com wrote: I suggest you better implement a location listener, which is much more light-weight than the busy polling you are implementing. You can cancel your subscription to location updates once you have one that satisfies you.Ludwig 2009/2/1 Anna PS annapowellsm...@googlemail.com Great - thank you. I'll remember to read the documentation next time :) I've pasted my code below in case anyone wants to borrow it: it keeps polling for up-to-date and accurate GPS data, up to a maximum of 10 seconds. If by then the GPS data is old or not accurate enough, it just returns false. The code feels a bit dubious, but it seems to do the job. Anna long locationTime = location.getTime(); long currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; float accuracy = location.getAccuracy(); int count = 0; // Wait for accurate GPS data, up to a maximum of 10 seconds before // throwing an error while (((timeDifference 10) || (accuracy 20.0)) (count 20)) { location = locationmanager.getLastKnownLocation(gps); locationTime = location.getTime(); currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000;
[android-developers] Re: Age of GPS data
Hi Ludwig, Thanks for the suggestion. I do implement a listener, when the application opens. But I found that the GPS data using getLastKnownLocation was often out of date or inaccurate, and that caused me real problems, since it's a mapping application and the data needs to be very accurate - I need to warn the user if it isn't. Hence the polling to make sure it's up to date. (I run the polling in a background thread.) I've pasted my listener code below, that I call from onCreate... do you suggest any changes? thanks, Anna //This function called from onCreate... public boolean testProviders() { Log.d(LOG_TAG, testProviders); String location_context = Context.LOCATION_SERVICE; locationmanager = (LocationManager) getSystemService (location_context); listener = new LocationListener() { public void onLocationChanged(Location location) { } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }; locationmanager.requestLocationUpdates(gps, 500, 0, listener); Log.d(LOG_TAG, Checking location with provider + gps); location = locationmanager.getLastKnownLocation(gps); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); latString = latitude.toString(); longString = longitude.toString(); Log.d(LOG_TAG, Location found: latitude + latString + and longitude + longString); return true; } else { Log.d(LOG_TAG, Location not found); return false; } On 2 Feb, 12:50, Ludwig ludwigbrinckm...@gmail.com wrote: I suggest you better implement a location listener, which is much more light-weight than the busy polling you are implementing. You can cancel your subscription to location updates once you have one that satisfies you.Ludwig 2009/2/1 Anna PS annapowellsm...@googlemail.com Great - thank you. I'll remember to read the documentation next time :) I've pasted my code below in case anyone wants to borrow it: it keeps polling for up-to-date and accurate GPS data, up to a maximum of 10 seconds. If by then the GPS data is old or not accurate enough, it just returns false. The code feels a bit dubious, but it seems to do the job. Anna long locationTime = location.getTime(); long currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; float accuracy = location.getAccuracy(); int count = 0; // Wait for accurate GPS data, up to a maximum of 10 seconds before // throwing an error while (((timeDifference 10) || (accuracy 20.0)) (count 20)) { location = locationmanager.getLastKnownLocation(gps); locationTime = location.getTime(); currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; accuracy = location.getAccuracy(); Log.d(LOG_TAG, getting up to date GPS data, time diff = + timeDifference + accuracy = + accuracy + count = + count); try { Thread.currentThread(); Thread.sleep(500); } catch (InterruptedException ie) { } count++; } // No accurate GPS data? Exit here and warn the user if ((timeDifference 10) || (accuracy 20.0)) { return false; } On 27 Jan, 03:38, gjs garyjamessi...@gmail.com wrote: Hi, Subtract the Location.getTime() value from the current time to get the age of the last fix. Seehttp:// code.google.com/android/reference/android/location/Location.html Regards On Jan 23, 10:07 am, Anna PS
[android-developers] Re: Age of GPS data
The Location object has a getTime() method that should supply you with the age of the fix. The getLastKnownLocation() call does not miraculously have another source of location information than what you would get with the upcall. Set the time in requestLocationUpdates to 0 to get notifications as frequently as possible: that way you have the most up-to-date location your device can give you. Ludwig 2009/2/4 Anna PS annapowellsm...@googlemail.com Hi Ludwig, Thanks for the suggestion. I do implement a listener, when the application opens. But I found that the GPS data using getLastKnownLocation was often out of date or inaccurate, and that caused me real problems, since it's a mapping application and the data needs to be very accurate - I need to warn the user if it isn't. Hence the polling to make sure it's up to date. (I run the polling in a background thread.) I've pasted my listener code below, that I call from onCreate... do you suggest any changes? thanks, Anna //This function called from onCreate... public boolean testProviders() { Log.d(LOG_TAG, testProviders); String location_context = Context.LOCATION_SERVICE; locationmanager = (LocationManager) getSystemService (location_context); listener = new LocationListener() { public void onLocationChanged(Location location) { } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }; locationmanager.requestLocationUpdates(gps, 500, 0, listener); Log.d(LOG_TAG, Checking location with provider + gps); location = locationmanager.getLastKnownLocation(gps); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); latString = latitude.toString(); longString = longitude.toString(); Log.d(LOG_TAG, Location found: latitude + latString + and longitude + longString); return true; } else { Log.d(LOG_TAG, Location not found); return false; } On 2 Feb, 12:50, Ludwig ludwigbrinckm...@gmail.com wrote: I suggest you better implement a location listener, which is much more light-weight than the busy polling you are implementing. You can cancel your subscription to location updates once you have one that satisfies you.Ludwig 2009/2/1 Anna PS annapowellsm...@googlemail.com Great - thank you. I'll remember to read the documentation next time :) I've pasted my code below in case anyone wants to borrow it: it keeps polling for up-to-date and accurate GPS data, up to a maximum of 10 seconds. If by then the GPS data is old or not accurate enough, it just returns false. The code feels a bit dubious, but it seems to do the job. Anna long locationTime = location.getTime(); long currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; float accuracy = location.getAccuracy(); int count = 0; // Wait for accurate GPS data, up to a maximum of 10 seconds before // throwing an error while (((timeDifference 10) || (accuracy 20.0)) (count 20)) { location = locationmanager.getLastKnownLocation(gps); locationTime = location.getTime(); currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; accuracy = location.getAccuracy(); Log.d(LOG_TAG, getting up to date GPS data, time diff = + timeDifference + accuracy = + accuracy + count = + count); try { Thread.currentThread(); Thread.sleep(500); } catch (InterruptedException ie) { } count++; }
[android-developers] Re: Age of GPS data
I suggest you better implement a location listener, which is much more light-weight than the busy polling you are implementing. You can cancel your subscription to location updates once you have one that satisfies you.Ludwig 2009/2/1 Anna PS annapowellsm...@googlemail.com Great - thank you. I'll remember to read the documentation next time :) I've pasted my code below in case anyone wants to borrow it: it keeps polling for up-to-date and accurate GPS data, up to a maximum of 10 seconds. If by then the GPS data is old or not accurate enough, it just returns false. The code feels a bit dubious, but it seems to do the job. Anna long locationTime = location.getTime(); long currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; float accuracy = location.getAccuracy(); int count = 0; // Wait for accurate GPS data, up to a maximum of 10 seconds before // throwing an error while (((timeDifference 10) || (accuracy 20.0)) (count 20)) { location = locationmanager.getLastKnownLocation(gps); locationTime = location.getTime(); currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; accuracy = location.getAccuracy(); Log.d(LOG_TAG, getting up to date GPS data, time diff = + timeDifference + accuracy = + accuracy + count = + count); try { Thread.currentThread(); Thread.sleep(500); } catch (InterruptedException ie) { } count++; } // No accurate GPS data? Exit here and warn the user if ((timeDifference 10) || (accuracy 20.0)) { return false; } On 27 Jan, 03:38, gjs garyjamessi...@gmail.com wrote: Hi, Subtract the Location.getTime() value from the current time to get the age of the last fix. Seehttp:// code.google.com/android/reference/android/location/Location.html Regards On Jan 23, 10:07 am, Anna PS annapowellsm...@googlemail.com wrote: Hi When you get GPS location using getLastKnownLocation, is there a way to check how old the data is, i.e. when the location was last updated? I'm noticing that sometimes my app is giving me an out-of-date location (usually because the sky is not visible when the app starts) - it'd be good to warn the user about this. It's possible to check the age of the data on the iPhone I believe, is it possible in Android? thanks! Anna --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Age of GPS data
Great - thank you. I'll remember to read the documentation next time :) I've pasted my code below in case anyone wants to borrow it: it keeps polling for up-to-date and accurate GPS data, up to a maximum of 10 seconds. If by then the GPS data is old or not accurate enough, it just returns false. The code feels a bit dubious, but it seems to do the job. Anna long locationTime = location.getTime(); long currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; float accuracy = location.getAccuracy(); int count = 0; // Wait for accurate GPS data, up to a maximum of 10 seconds before // throwing an error while (((timeDifference 10) || (accuracy 20.0)) (count 20)) { location = locationmanager.getLastKnownLocation(gps); locationTime = location.getTime(); currentTime = System.currentTimeMillis(); timeDifference = (currentTime - locationTime) / 1000; accuracy = location.getAccuracy(); Log.d(LOG_TAG, getting up to date GPS data, time diff = + timeDifference + accuracy = + accuracy + count = + count); try { Thread.currentThread(); Thread.sleep(500); } catch (InterruptedException ie) { } count++; } // No accurate GPS data? Exit here and warn the user if ((timeDifference 10) || (accuracy 20.0)) { return false; } On 27 Jan, 03:38, gjs garyjamessi...@gmail.com wrote: Hi, Subtract the Location.getTime() value from the current time to get the age of the last fix. Seehttp://code.google.com/android/reference/android/location/Location.html Regards On Jan 23, 10:07 am, Anna PS annapowellsm...@googlemail.com wrote: Hi When you get GPS location using getLastKnownLocation, is there a way to check how old the data is, i.e. when the location was last updated? I'm noticing that sometimes my app is giving me an out-of-date location (usually because the sky is not visible when the app starts) - it'd be good to warn the user about this. It's possible to check the age of the data on the iPhone I believe, is it possible in Android? thanks! Anna --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Age of GPS data
Hi, Subtract the Location.getTime() value from the current time to get the age of the last fix. See http://code.google.com/android/reference/android/location/Location.html Regards On Jan 23, 10:07 am, Anna PS annapowellsm...@googlemail.com wrote: Hi When you get GPS location using getLastKnownLocation, is there a way to check how old the data is, i.e. when the location was last updated? I'm noticing that sometimes my app is giving me an out-of-date location (usually because the sky is not visible when the app starts) - it'd be good to warn the user about this. It's possible to check the age of the data on the iPhone I believe, is it possible in Android? thanks! Anna --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---