Best way to get my current location just once

44 views
Skip to first unread message

cubiq1

unread,
Aug 23, 2014, 6:10:08 AM8/23/14
to codenameone...@googlegroups.com
Hi,

What would be the best, no-nonsense way to get my current location just once? (and then dispose of the LocationListener.)

LocationManager.getLocationManager().getCurrentLocationSync(timeout) would be perfect but I need the user to be able to cancel the operation if it's taking too long.

I've tried something like this but the GPS icon remains active on my phone, meaning the LocationListener isn't being disposed of:

        LocationManager.getLocationManager().setLocationListener(new LocationListener() {
           
           
public void providerStateChanged(int newState) {
               
Dialog.show("Location", "State changed", "OK", null);
           
}

           
public void locationUpdated(Location location) {
               
               
Dialog.show("Location (" + i++ + ")", location.getLongitude() + ", " + location.getLatitude(), "OK", null);
               
LocationManager.getLocationManager().setLocationListener(null);
           
}
       
});

Many thanks

Shai Almog

unread,
Aug 23, 2014, 1:01:09 PM8/23/14
to codenameone...@googlegroups.com
Hi,
that is why we are open source. Just open location manager and look at what we did in that method.
Reply all
Reply to author
Forward
0 new messages