There's no magic to the PASSIVE_PROVIDER. While you don't need to turn
on a location provider to use passive, *somebody* must have turned
something on, otherwise there won't be any updated locations. Passive
let's you piggyback on someone else's location updates. Which means,
if your location-aware widget or clock is updating often enough,
passive should give you a reasonable location. The challenge is to
know when to trust a result from passive. Anything that is location
aware can enable a provider (assuming it has permissions to do so),
get a location result, then disable that provider until it wants
another location. This has been the recommended advice if you don't
need frequent location updates so the location hardware is off as much
as possible. If you check for enabled location providers (using
getProviders() with the enabledOnly parameter), you could find that
they're all off. On the positive side, a location should tell you when
it was acquired (using getTime()). You could use that to make a
judgment call on whether or not the retrieved location is recent
enough for your app to trust it.

- dave

On Feb 20, 8:17 am, Mark Murphy <[email protected]> wrote:
> On Sat, Feb 19, 2011 at 8:34 PM, Jake Colman <[email protected]> wrote:
> > If my phone is running a location-aware clock or a location-aware
> > weather widget, would getLastKnownLocation() be guaranteed to return a
> > value in my app?
>
> There are no guarantees in life.
>
> For example, a "location-aware clock" might only check location
> sporadically (e.g., daily).
>
> > Or is that the point of the 'passive' provider?
>
> The passive provider is so you can get location data without
> necessarily turning anything on (e.g., GPS radio).
>
> > With my widget installed on my HTC EVO, which runs the HTC standard
> > location-aware clock, it always knows where it is as I travel from home
> > to work.  That would imply that my app's call to getLastKnownLocation
> > returned results since the phone knew where it was.  Does that make
> > sense?
>
> Yes. Unless your app is only for you, though, you can't exactly rely on that.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Warescription: Three Android Books, Plus Updates, One Low Price!

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