У меня было следующее:
function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 47.371068, lng: 8.538540},
zoom: 500,
zoomControl: false,
disableDefaultUI: true
});
// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_CENTER].push(input);
document.getElementById("bottomBar").style.opacity = "0.0";
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});
var markers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
Это работает, но не ограничивается 1 страной, только когда я печатаю в строке поиска.
Я попробовал следующее:
// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var options = {
componentRestrictions: {country: 'fr'}};
var searchbox = new google.maps.places.Autocomplete(input,options);
map.controls[google.maps.ControlPosition.TOP_CENTER].push(input);
document.getElementById("bottomBar").style.opacity = "0.0";
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});
var markers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
Поиск «работает», так как я могу получить местоположения только во Франции, однако, когда я нажимаю на них, карта не обновляется.
Что здесь не так?
полная версия здесь