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

I'm pretty sure I answered your question when you asked it a few days ago.

> 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 generally be null at this point.

In the real world, GPS takes time to get a fix, perhaps tens of seconds,
perhaps never depending on where the device is. You only asked for the
radio to be turned on in the previous statement -- the fix will not be
ready one line later in your code.

>        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();
>
>
>        } else {
>
>                latPoint = 111.1111111; // means location is Null
>        }

You will need to delay this work until you get your first fix, such as by
putting it in your locationListener. And you will need to deal with the
possibility that you will never get a fix, either because GPS is disabled,
or because the device is someplace where it cannot get a fix.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



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