我需要 Google Place Autocomplete 这些值:
alert(
place.name + // Works
place.geometry.location.lat() + // Works
place.country + // Not works - what is correct value to get country value?
place.state // Not works - what is correct value to get state value?
);
它适用于 place.name和place.geometry,但不适用于place.country和place.state。
如何获得其他两个值?谢谢你的任何建议。
整体功能:
function initializeGoogleMaps() {
var input = document.getElementById("googleMapsSearch");
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(
autocomplete,
"place_changed",
function() {
var place = autocomplete.getPlace();
alert(
place.name + // Works
place.geometry.location.lat() + // Works
place.country + // Not works - what is correct value to get country value?
place.state // Not works - what is correct value to get state value?
);
document.getElementById("city").value = place.name; // Works
document.getElementById("cityLat").value = place.geometry.location.lat(); // Works
document.getElementById("country").value = place.country; // Not works
document.getElementById("state").value = place.state; // Not works
});
}