Georgy wrote:
> I know this has been discussed over and over now but I just got it
> workign and it works perfectly on the emulator when I mock the
> location with long and lat however, I am still getting NULL in the
> location when I run the code on my phone.
>
> here's the main code
>
> ...
>
> // Get my current location
> locationListener = new MyLocationListener();
> LocationManager manager = (LocationManager) getSystemService
> (LOCATION_SERVICE);
> manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
> 0, 0,locationListener);
> Location loc = manager.getLastKnownLocation("gps");
loc will almost certainly be null at this point.
Your GPS radio will be turned on sometime after the
requestLocationUpdates() call. However, it takes quite a long time to
get a GPS fix, particularly on the G1. Tens of seconds is well within
reason. It is very unlikely that you will have a location already on the
next statement.
> if(loc != null) {
> latPoint = manager.getLastKnownLocation("gps").getLatitude
> ();
> lngPoint = manager.getLastKnownLocation("gps").getLongitude
> ();
>
> // Create a point of it
> GeoPoint point = new GeoPoint((int) (latPoint * 1E6), (int)
> (lngPoint * 1E6));
> // Animate the map to the location
> mc.animateTo(point);
> mc.setZoom(20);
> mapView.setSatellite(true);
> mapView.invalidate();
You're going to need to delay this stuff until you get a fix from GPS.
Your locationListener object will be invoked at that point.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Android App Developer Books: http://commonsware.com/books.html
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---