Akshat Agarwal Akshat Agarwal - 1 year ago 94
Android Question

How to get users current location coordinates using google maps API and not location manager

Using google maps API v2, I know that

myMap.setMyLocationEnabled(true);
will let me show the users location on the google map, however I also want the coordinates of this location to be shown underneath the google map. I dont want to use

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);


since this looks like an overkill. We already have the location of the user (the on pin pointed on the map), now I just need its coordinate values.
How do I get that? I cant find some property such as
myLocation.getCurrentCoordinates()

Answer Source

I ended up using LocationClient to get my current location and relying upon getLastLocation()

private LocationClient locationClient;
private Location myLocation = null;
locationClient = new LocationClient(this, this, this);
locationClient.connect();

    @Override
public void onConnected(Bundle arg0) {
    myLocation = locationClient.getLastLocation();
}

This might not always be accurate, however I only needed it once and didnt want to use locationChangedListeners.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download