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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to