try this way extract Latitude
and Longitude
from LatLng
@Override
public void onMapLongClick(LatLng latLng) {
Double lat=latLng.latitude;
Double longi=latLng.longitude;
.........
..........
//do your job
}
Pregunta
I want to display adress on marker clicked on the android map. I used GeoCoder for getting adress but OnMapLongClick function doesn't have lat,long parameters. It's parameter is (LatLng latlng). My code below ;
@Override
public void onMapLongClick(LatLng latLng) {
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(lat, lng, 1);
if (addresses.size() > 0) {
for (int index = 0;
index < addresses.get(0).getMaxAddressLineIndex(); index++)
filterAddress += addresses.get(0).getAddressLine(index) + " ";
}
}catch (IOException ex) {
ex.printStackTrace();
}catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
googleMap.addMarker(new MarkerOptions().position(latLng).title(filterAddress)).showInfoWindow();
markerClicked = false;
}
How can I parse or how can i convert latlng object to lat, lng parameters?
Solución
try this way extract Latitude
and Longitude
from LatLng
@Override
public void onMapLongClick(LatLng latLng) {
Double lat=latLng.latitude;
Double longi=latLng.longitude;
.........
..........
//do your job
}
Otros consejos
With a small google search, LatLng
class
Use public fields latitude
and longitude
to read the two values.
List<Address> addresses = geoCoder.getFromLocation(latLng.latitude, latLng.longitude, 1);
You can use latlng.latitude
and latlng.longitude
to get lat and lng parameters.