Autocomplete 带有国家过滤器下拉列表的地址表单-谷歌地图
我正在尝试为自动完成的地址表单添加“国家”筛选器。 因此,当用户选择某个国家时,google自动完成会根据该国家过滤地址。 由于某些原因,当用户更改国家/地区时,我无法让更改事件发生,而且它似乎总是停留在“我们”上 我做错了什么 这是我的小提琴: 以下是更改筛选的代码:Autocomplete 带有国家过滤器下拉列表的地址表单-谷歌地图,autocomplete,maps,filtering,countries,Autocomplete,Maps,Filtering,Countries,我正在尝试为自动完成的地址表单添加“国家”筛选器。 因此,当用户选择某个国家时,google自动完成会根据该国家过滤地址。 由于某些原因,当用户更改国家/地区时,我无法让更改事件发生,而且它似乎总是停留在“我们”上 我做错了什么 这是我的小提琴: 以下是更改筛选的代码: function initAutocomplete() { // Create the autocomplete object, restricting the search predictions to // geograph
function initAutocomplete() {
// Create the autocomplete object, restricting the search predictions to
// geographical location types.
autocomplete = new google.maps.places.Autocomplete(
document.getElementById('autocomplete'), {types: ['geocode'],
componentRestrictions: countryRestrict});
places = new google.maps.places.PlacesService(map);
autocomplete.addListener('place_changed', onPlaceChanged);
// Add a DOM event listener to react when the user selects a country.
document.getElementById('country').addEventListener(
'change', setAutocompleteCountry);
// Set the country restriction based on user input.
// Also center and zoom the map on the given country.
function setAutocompleteCountry() {
var country = document.getElementById('country').value;
if (country == 'all') {
autocomplete.setComponentRestrictions({'country': []});
//map.setCenter({lat: 15, lng: 0});
//map.setZoom(2);
} else {
autocomplete.setComponentRestrictions({'country': country});
//map.setCenter(countries[country].center);
//map.setZoom(countries[country].zoom);
}
clearResults();
//clearMarkers();
}