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


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;

var res = results1[key][key1].toString().split("(");
console.log(" latlong::"+res);
var res2= res[1].split(",");
console.log(" latlong::"+res2);
console.log(" latlong::"+latlongFrom[0]);
var res3=res2[1].split(")");
console.log(" latlong::"+res3[0]);
console.log(" latlong::"+latlongFrom[1]);

This is what I have done. The res contains the value of (lat,long).

To get Latitude and Longitude your have to declare 2 double variables.

map.setOnMapClickListener(new OnMapClickListener() {

    public void onMapClick(LatLng latln) {
        double latitude, longitude;


For newer version please use:

double lat =;
double lng = latlng.lng;

as latlng.latitude and latlng.longitude or and latlng.lng() will give compilation error.

This is for Android solution

public void onMapClick(LatLng latln) {
    String s = latln.toString();
    String[] latLng = s.substring(10, s.length() - 1).split(",");
    String sLat = latLng[0];
    String sLng = latLng[1];
    Toast.makeText(MapsActivity.this, "Latitude is: "+sLat+", Longtitude is: "+sLng, Toast.LENGTH_LONG).show();

Need Your Help

Factors in R: more than an annoyance?

r language-design internals r-factor

One of the basic data types in R is factors. In my experience factors are basically a pain and I never use them. I always convert to characters. I feel oddly like I'm missing something.

Reload Express.js routes changes without manually restarting server

javascript node.js express

I tried express-livereload, but it just reloaded view files.