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..
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.
getLastKnownLocation(LocationManager. GPS_PROVIDER); double longitude = location. getLongitude(); double latitude = location. getLatitude();
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).
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With