gpt4 book ai didi

javascript - Google 地点,类型区域的严格限制

转载 作者:行者123 更新时间:2023-11-28 03:06:35 29 4
gpt4 key购买 nike

我正在尝试返回仅限于某种区域的自动完成结果 -

the (regions) type collection instructs the Places service to return any result matching the following types: - locality - sublocality - postal_code - country - administrative_area_level_1 - administrative_area_level_2

[https://developers.google.com/places/web-service/autocomplete][1]

但也受到欧盟周围的严格限制。当我使用类型(城市)时,相同的代码可以工作。当我将类型更改为区域时,它会放弃严格的界限。区域与严格边界不兼容吗?我错过了一些愚蠢的事情吗?同时删除区域:'EU' 参数不会执行任何操作。

function setup_autocomplete(){

//console.log( 'setting up autocomplete' );
//setbounds around EU
var circle = new google.maps.Circle({ center: new google.maps.LatLng( 54.0000, -4.0000 ), radius: 60000 });

var input = document.getElementById('home-carousel-location-input') || false,
options = {
region:'EU',
types: ['(regions)'],
bounds: circle.getBounds(),
strictbounds: true

}, autocomplete;

if( input ){

autocomplete = new google.maps.places.Autocomplete(input, options);
}
}

最佳答案

您的地点自动完成实现似乎不太正确,因为您使用的是不受支持的 region: 参数。这是 supported options 的列表可以在自动完成对象上设置。

您可以删除region: 参数。您可以使用 strictbounds:bounds: 参数设置区域限制。

autocomplete.setOptions({
strictBounds: true,
bounds: circle.getBounds(),
types: ['(regions)']
});

您可以尝试示例 jsbin 演示 here .

在演示中,我为圆设置了一个 fillColor: 来可视化半径,并添加了一个带有 fillColor: 的矩形来可视化严格边界。地点自动完成服务将返回与 (regions) type 匹配的任何结果。在范围内。

关于javascript - Google 地点,类型区域的严格限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60549965/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com