Google商家信息自动填充API不会偏向于位置

时间:2017-09-09 11:26:03

标签: google-places-api google-places

我正在使用自动填充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]

印度的结果仍未优先于其他回应。

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

1 个答案:

答案 0 :(得分:-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]