Javascript Google MAP Places API不返回lat lang
我正在使用谷歌地图的地方API和自动完成功能。下面是示例代码Javascript Google MAP Places API不返回lat lang,javascript,angular,Javascript,Angular,我正在使用谷歌地图的地方API和自动完成功能。下面是示例代码 this.autocomplete = new google.maps.places.Autocomplete(this.autocompleteElement.nativeElement,{ componentRestrictions:{'country':'IN'}, types:[] }); // Bind the map's bounds (viewport) property to
this.autocomplete = new google.maps.places.Autocomplete(this.autocompleteElement.nativeElement,{
componentRestrictions:{'country':'IN'},
types:[]
});
// Bind the map's bounds (viewport) property to the autocomplete object,
// so that the autocomplete requests use the current map bounds for the
// bounds option in the request.
//this.autocomplete.bindTo('bounds', map);
// Set the data fields to return when the user selects a place.
this.autocomplete.setFields(
['address_components', 'geometry.location', 'icon']);
this.autocomplete.addListener('place_changed',()=>{
let place=this.autocomplete.getPlace();
console.log(place);
if (!place.geometry) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
console.log("No details available for input: '" + place.name + "'");
return;
}
})
无论何时调用gePlace(),它都只返回name属性。请指点。我相信您可以使用place\u id获得此信息 在if语句中尝试以下操作:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'placeId': place.place_id }, function (results, status)
{
// return if there was a problem
if (status !== 'OK') return;
// get the co-ordinates
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
});