Jai Kumar Jai Kumar - 1 year ago 141
Android Question

Getting latitude and longitude from latlng object in android

I am trying to get latitude and longitude on the Googlemap v2.. I have set the onclick listener for mapragment object using the code

map.setOnMapClickListener(new OnMapClickListener() {

public void onMapClick(LatLng latln) {
// TODO Auto-generated method stub

String s=latln.toString();



It provides be the latitude and longitude coordinates in the format lat/lng: (xx.xxxxxx,yy.yyyyy)
I need the exact method to get latitude and longitude data.. I dont want to parse the data using split and get the coordinates..

Answer Source

This can easily be found in the Google Maps API reference:

public final class LatLng

public final double latitude

Latitude, in degrees. This value is in the range [-90, 90].

public final double longitude

Longitude, in degrees. This value is in the range [-180, 180).

So in your example you should call:

double lat = latlng.latitude;
double lng = latlng.longitude;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download