get Lat Lang from a place_id returned by autocomplete place api

前端 未结 12 1443
情深已故
情深已故 2021-02-02 05:58

I am searching the place in my apps using the google autocomplete place api and now I want to get latitude and longitude of the place that i have searched. How to get latitude a

12条回答
  •  北海茫月
    2021-02-02 06:28

    add these line under function

     autocomplete.addListener('place_changed', function() {});
     var place = autocomplete.getPlace();
     autocomplete.setFields(['place_id', 'geometry', 'name', 'formatted_address']);
     var lng = place.geometry.location.lng();
     var lat = place.geometry.location.lat();
     var latlng = {lat , lng};
     console.log(latlng);
    

提交回复
热议问题