【问题标题】:Mixed results on google places autocomplete谷歌地方自动完成的混合结果
【发布时间】:2016-03-16 13:03:54
【问题描述】:

我有这个代码

    var input, defaultBounds, autocomplete_normal;
    input = (document.getElementById('search_location'));
    defaultBounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(-90, -180),
        new google.maps.LatLng(90, 180)
    );
    var options = {
        bounds: defaultBounds,
       types: ['(cities)']
    };

    autocomplete_normal = new google.maps.places.Autocomplete(input, options);
    google.maps.event.addListener(autocomplete_normal, 'place_changed', function () {
        var place = autocomplete_normal.getPlace();  
        console.log(place);
    });

当我搜索“葡萄牙科英布拉”时,Api 的地方会将“科英布拉”作为“地点”返回 - 应该如此。

但是,如果我将 types: ['(cities)'] 替换为 types: ['geocode'] ,则“Coimbra”将返回为“administrative_area_level_2”,并且没有其他关于位置的信息。

类型为 ['(cities)'] 的代码用于提交页面以获取城市。类型为 ['geocode'] 的代码用于搜索表单,在这种情况下不会返回正确的结果,因为“locality”变量为空。

我尝试将地理编码替换为“(区域)”,但结果相同。你能告诉我为什么会这样吗?为什么这只发生在某些地方?

【问题讨论】:

    标签: google-maps google-maps-api-3 google-places-api


    【解决方案1】:

    Administrative_area 2 也是城市...来自他们的文档:

    administrative_area_level_2 表示国家级以下的二级民事实体。在美国,这些行政级别是县。并非所有国家都表现出这些行政级别。'

    地理编码响应不包含“城市”,因此它们被还原为管理区域_2。

    【讨论】:

    • 我认为你错了 - 地理编码确实包含城市 - 例如“里斯本”、“丰沙尔”、“波尔图”(相同国家/地区差异城市)返回为“地区”。
    • 哎呀,我误解了这个问题。科英布拉是葡萄牙的一个地方和一个自治市en.wikipedia.org/wiki/Coimbra。您可以从自动完成中选择您想要的。将“Coimbra”放在这里 developers.google.com/maps/documentation/javascript/examples/… 并注意这两个选择。
    • 无论您选择什么,科英布拉或科英布拉区,我都会得到类似的结果(没有地点)。在位置响应prntscr.com/aghl88 上查看带有 console.log 的屏幕截图
    • 我认为在城市名称与地区名称相同的情况下会发生这种情况。
    猜你喜欢
    • 1970-01-01
    • 2014-05-21
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多