【问题标题】:Google Places Autocomplete API does not bias for locationGoogle Places Autocomplete API 不会偏向于位置
【发布时间】:2017-09-09 11:26:03
【问题描述】:

我正在使用 Autocomplete API 通过以下请求获取当前位置“有偏差”的结果:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=kuli&types=(regions)&key=[KEY]

API 返回以下响应:

{
"predictions" : [
    {
        "description" : "Kulim Kedah Malaysia",
        ...
        "types" : [ "locality", "political", "geocode" ]
    },
    {
        "description" : "Kuliyapitiya, North Western Province, Sri Lanka",
        ...
        "types" : [ "locality", "political", "geocode" ]
    },
    {
        "description" : "Kulithalai, Tamil Nadu, India",
        ...
        "types" : [ "locality", "political", "geocode" ]
    },
    {
        "description" : "Kuligów, Poland",
        ...
        "types" : [ "locality", "political", "geocode" ]
    },
    {
        "description" : "Kulin, Western Australia, Australia",
        ...
        "types" : [ "locality", "political", "geocode" ]
    }
],
"status" : "OK"
}

正如您在上面看到的,响应不会偏向于位置。文档说返回“附近”位置时会考虑 IP 地址。但是从响应来看,印度位置并没有优先于其他位置返回(请求IP地址是印度)。

甚至,当我用 lat,long 传递 location 参数时:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=kuli&types=(regions)&location=lat,long&key=[KEY]

印度的结果仍然没有优先于其他响应。

如何使 API 返回位置“偏向”于 IP 地址或位置坐标?感谢您的时间。

【问题讨论】:

    标签: google-places-api google-places


    【解决方案1】:

    将组件添加到您的网址:&components=country:IN

    https://maps.googleapis.com/maps/api/place/autocomplete/json?input=kuli&components=country:IN&types=(regions)&location=lat,long&key=[KEY]
    

    【讨论】:

    • 谢谢Subbu。但我不想将搜索限制在特定国家/地区。我只希望 API 在搜索结果的顶部返回“更近”的位置。
    • 添加类型和半径 "&types=geocode&location=latitude,longitude&radius=1000&sensor=true" 了解更多详情developers.google.com/places/web-service/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    相关资源
    最近更新 更多