What I do.
I never even look at lastKnownLocation; as you state it might be old
like dustballs.
This means I will only process locations received fresh from
onLocationChanged().
As you note, this may never happen. So keep users informed
accordingly! If you couldn't acquire a fix, let the user know.


On Apr 16, 3:41 pm, Anna PS <[email protected]> wrote:
> > On Apr 16, 12:45 am, JP <[email protected]> wrote:
> > On Apr 15, 8:35 am, Anna PS <[email protected]> wrote:
>
> > > Yet in my log files, I can
> > > still see the Android NetworkLocationProvider logging
> > > onCellLocationChanged events. Is this a bug in my code?
>
> > Without diving into your code. Double check it by using GPS. GPS is
> > considerably more accurate than base station based triangulation,
> > which may not result in location changes even if you move a hundred
> > meters (in my experience, anyway).
>
> The basic issue is this. I don't want to accidentally end up with a
> LastKnownLocation that's days out of date, so I have to check the age
> of the location fix.
>
> Since the GPS time (from location.getTime()) and the system time can
> be quite different (as <a href="http://www.mail-archive.com/android-
> [email protected]/msg47517.html">discussed here</a>,
> comparing the two doesn't work. The only reliable way seems to be:
>
> - get an initial location from getLastKnownLocation
> - wait for a location update from onLocationChanged
> - compare the age of the two to make sure the latter is newer.
>
> However, I'd also like to write code that handles gracefully the
> possibility that the user is (say) indoors, and therefore won't get an
> onLocationChanged event at all. (In which case, we should just take
> the LastKnownLocation, and never mind if it's out of date.)
>
> I seem to be at a logical impasse. What can I do? I can't wait for an
> onLocationChanged event if it's never going to happen - my code will
> hang forever! But equally I can't just take getLastKnownLocation every
> time - it might be wildly inaccurate.
>
> Maybe I need to run some kind of timer in the code, to check how long
> we've been waiting for an onLocationChanged. Does that seem like the
> best idea?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to