Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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() {

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


        String s=latln.toString();

        Log.w("dsfdsf",""+s);

    }
});

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

like image 793
Jai Kumar Avatar asked Mar 07 '13 06:03

Jai Kumar


People also ask

How do you find the latitude and longitude of a LatLng?

setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng latln) { // TODO Auto-generated method stub String s=latln. toString(); Log. w("dsfdsf",""+s); } }); It provides be the latitude and longitude coordinates in the format lat/lng: (xx.

How do I find the latitude and longitude of a device?

getLastKnownLocation(LocationManager. GPS_PROVIDER); double longitude = location. getLongitude(); double latitude = location. getLatitude();


2 Answers

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

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

like image 101
khanna..abhishek Avatar answered Sep 24 '22 04:09

khanna..abhishek


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;
like image 42
Matt Handy Avatar answered Sep 25 '22 04:09

Matt Handy