【问题标题】:Google places, strictbounds with type regions谷歌地方,类型区域的严格限制
【发布时间】:2020-06-18 08:33:49
【问题描述】:

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

(regions) 类型集合指示 Places 服务返回 任何匹配以下类型的结果: - 地方性 - 次区域性 - 邮政编码 - 国家 - 行政区域级别_1 - 行政区域级别_2

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

但也受到欧盟的严格限制。当我使用类型(城市)时,同样的代码可以工作。当我将类型更改为区域时,它会放弃严格的界限。区域是否与严格边界不兼容?我错过了什么愚蠢的东西吗?也删除了 region:'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);
        }
    }

【问题讨论】:

    标签: javascript google-maps autocomplete google-places-api google-places


    【解决方案1】:

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

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

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

    您可以尝试示例 jsbin 演示 here

    在演示中,我将fillColor: 设置为圆形以可视化半径,并添加一个带有fillColor: 的矩形以可视化严格边界。 Places Autocomplete 服务将返回与(regions)type 匹配的任何结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-20
      • 2018-08-12
      • 2014-05-12
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多