Closed serval92 closed 6 years ago
Hey serval,
You can currently get the lat and lng from the selected place by reading from the placeResult
which is returned to the onChange
callback. This would be easiest way to get the lat and lng each time a place is changed:
$("#myInput").geocomplete({
onChange: function(name, result) {
// this is the LatLng for the selected location
var location = result.geometry.location;
}
});
Thank you for your answer really fast ! I'm going to study that.
I have tried var location = result.geometry.location;
. But couldn't get the lat and lng from the selected place.
Here is my output.
How could I get the lat and lng from the selected place?
result.geometry.location
is a LatLng class which has the methods lat()
and lng()
$("#myInput").geocomplete({
onChange: function(name, result) {
// this is the LatLng for the selected location
var location = result.geometry.location;
var lat = location.lat();
var lng = location.lng();
}
});
Thanks for the quick response. really appreciate.
Hi, Trent.
Could you add to your script an automatic geocoding to get lat and lng, please ? It would be very nice ! Thank you.