Dear all,

I am facing a strange issue and I'm certainly doing something
wrong ...

Here is the scenario :
I open my emulator
I send a geo fix via telnet
I open my app and try to be geolocated... getLastKnownLocation return
null (the first time, or the last position after opening "Map"), my
code is below
I open the "Maps" included app from Google.
I click on menu > My  Location and I am located to the position I sent
via the geo fix
I reopen my app and try to be geolocated ... and it works !

I read the doc and I don't understand what I am doing wrong :

Here is my code :
 public static LocationProvider getLocationProviderToUse(Context act)
{
        LocationManager locMgr = MapUtility.getBuiltLocationManager
(act);

        String name = locMgr.getBestProvider(new Criteria(), true);

        Log.d("MAP", "The best location provider is " + name);

        return locMgr.getProvider(name);
    }

    public static GeoPoint geoLocalize(Activity act)
        throws SecurityException {

        LocationProvider toUse = getLocationProviderToUse(act);

        LocationManager locMgr = MapUtility.getBuiltLocationManager
(act);

// Test but change nothing
// LocationListener listener = new LocationListener() {
//                public void onLocationChanged(Location location) {
//                }
//                public void onProviderDisabled(String provider) {
//                }
//                public void onProviderEnabled(String provider) {
//                }
//                public void onStatusChanged(String provider, int
status,
//                                Bundle extras) {
//                }
//        };

//        locMgr.requestLocationUpdates(toUse.getName(), 0, 0,
listener);

        Location current = locMgr.getLastKnownLocation(toUse.getName
());

        if (current != null) {
            Log.d("MAP", "Location : " + current.getLatitude() + ", "
+ current.getLongitude());
            GeoPoint p = new GeoPoint((int) (current.getLatitude() *
1000000), (int) (current.getLongitude() * 1000000));
            return p;
        } else{
                 Log.e("MAP", "Unable to get the last known position");
            return null;
        }
    }

   public static LocationManager getBuiltLocationManager(Context ctx)
{
        LocationManager mgr = (LocationManager) ctx.getSystemService
(Context.LOCATION_SERVICE);

        return mgr;
    }

-----------------------------------------------------

Coud you please help me in finding what is wrong or sending me a code
snippet ? By reading the Google reference documentation, a single call
to getlastknownlocation might be sufficient.... The best provider
returned is always "gps".

Thanks a lot for your help

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