javascript - 谷歌地图自动完成限制不起作用
问题描述
我有以下内容:
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;
}
搜索“有效”,因为我只能获得法国的位置,但是当我点击它们时,地图不会更新。
这里有什么问题?
完整版在这里
解决方案
推荐阅读
- php - 身份验证器登录返回预期的响应代码 235,但得到代码“535”,消息“535 身份验证数据不正确”
- javascript - 如何在 React Native 中的前一个函数完成后启动函数
- mongodb - Docker 容器启动并运行,但无法加载本地主机
- javascript - Bootstrap 4'modal.modal 不是函数'
- javascript - 有什么方法可以在 UTC 时区生成 Date 对象
- javascript - 无法使用 React 和材料表进行 DOM 操作
- ubuntu - Conky 问题:以前的壁纸或应用程序背景、双文本、旧的 conky 文本重叠
- java - 将 Android 语音识别文本发送到另一个活动
- python - 在 PyCharm 中没有添加 WSL python 解释器的菜单
- gremlin - Gremlin - 更新或插入多个顶点