Great post! thanks!

I spent hours trying to figure out why getLastKnownLocation() was
returning null. I agree with Sven, system should be able to cache the
"last known location" (pun intended) and return it when requested. It
shouldn't depend on location providers to be active. a single point of
failure i guess would be if none of the location providers were
activated since last power cycle. which is very unlikely since the
cell tower triangulation will almost always work.

On Mar 20, 7:05 am, Mark Murphy <mmur...@commonsware.com> wrote:
> Please do not simultaneously post to multiple lists.
>
>
>
> Sven Jacobs wrote:
> > I'm trying to access location data in the emulator but always receive
> > null values :( This is the code:
>
> > final LocationManager locationManager = (LocationManager)
> > getSystemService( Context.LOCATION_SERVICE );
>
> > if ( locationManager == null ) {
> > return;
> > }
>
> > final Criteria criteria = new Criteria();
>
> > criteria.setAccuracy( Criteria.ACCURACY_FINE );
> > criteria.setBearingRequired( false );
> > criteria.setSpeedRequired( false );
> > criteria.setAltitudeRequired( false );
> > criteria.setPowerRequirement( Criteria.NO_REQUIREMENT );
>
> > final String provider = locationManager.getBestProvider( criteria, false );
> > final Location loc = locationManager.getLastKnownLocation( provider );
>
> > As described here
> > <http://developer.android.com/guide/topics/location/index.html> I've set
> > a fixed position using the geo command on the telnet console but
> > getLastKnownLocation() always returns null. My app has the following
> > permissions set
>
> > ACCESS_MOCK_LOCATION
> > ACCESS_COARSE_LOCATION
> > ACCESS_FINE_LOCATION
>
> > Is there anything else that I'm missing?
>
> DDMS/geo only sets a simulated GPS fix (AFAIK -- that's certainly DDMS'
> behavior), and you have not turned on the GPS radio. You need to
> requestLocationUpdates() to turn on GPS, then set the fix. Then, your
> LocationListener will be notified of the fix, and after that point
> getLastKnownLocation() can return it as well.
>
> Here are two sample projects from a book demonstrating using
> requestLocationUpdates(), the first using only an activity, the second
> delegating the work to a service:
>
> http://github.com/commonsguy/cw-android/tree/master/Internet/Weather/http://github.com/commonsguy/cw-android/tree/master/Service/WeatherPlus/
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android 2.0 Programming Books:http://commonsware.com/books

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