tm4321 / jquery.geocomplete

A simple plugin for Google Maps Autocomplete.
http://projects.trentmentink.com/jquery_geocomplete/
MIT License
16 stars 8 forks source link

Include lat and lng in autocomplete #1

Closed serval92 closed 6 years ago

serval92 commented 7 years ago

Hi, Trent.

Could you add to your script an automatic geocoding to get lat and lng, please ? It would be very nice ! Thank you.

tm4321 commented 7 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;
  }
});
serval92 commented 7 years ago

Thank you for your answer really fast ! I'm going to study that.

tvbishan commented 6 years ago

I have tried var location = result.geometry.location;. But couldn't get the lat and lng from the selected place.

Here is my output. image

How could I get the lat and lng from the selected place?

tm4321 commented 6 years ago

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();
  }
});
tvbishan commented 6 years ago

Thanks for the quick response. really appreciate.