当我在google-maps上输入新地址时,我试图添加一个标记。输入地址,地图重新居中至该位置,但标记未显示在该新位置。我在代码中缺少一些小东西吗?
function initAutocomplete() {
// Create the autocomplete object
autocomplete = new google.maps.places.Autocomplete(document
.getElementById('autocomplete'));
// When the user selects an address from the dropdown, show the place selected
autocomplete.addListener('place_changed', onPlaceChanged);
}
function onPlaceChanged() {
place = autocomplete.getPlace();
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.
window.alert("No details available for input: '" + place.name + "'");
return;
}
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17);
}
marker.setPosition(place.geometry.location);
marker.setVisible(true);
}