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
-~----------~----~----~----~------~----~------~--~---

Reply via email to