Google Places API搜索奇怪行为

时间:2016-06-08 14:55:14

标签: google-maps google-places-api

我遇到这种情况: 我向Google Places API提出此请求:
     https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=25.0788005,-78.4699268&keyword=Tiki Bikini Hut&rankby=distance&key=MY_GOOGLE_API_KEY并且回复是:

    {
      "html_attributions": [],
      "results": [],
      "status": "ZERO_RESULTS"
    }

但是如果我尝试使用text_search:https://maps.googleapis.com/maps/api/place/textsearch/json?query=Bernie's &radius=15000&location=25.0788005,-78.4699268&key=MY_GOOGLE_API_KEY API会返回一个我搜索的地方。

此外,如果我在Google" Tiki Bikini Hut Bahamas"上搜索,Google会返回这是巴哈马群岛现有的谷歌地点。 enter image description here

任何人都可以帮助解释我为什么当我尝试附近的搜索时我会收到ZERO_RESULTS,但是如果我尝试文字搜索,我会得到这个地方吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

事实上,正如meucaa所指出的,根据Google Documentation

radius是必需的参数。

即使是半径为0,您也可以获得信息,如下所示:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Tiki%20Bikini&location=25.0788005%2C-78.4699268&radius=0&key=YOUR_api_key

但是,如果您使用的是附近的搜索,则会有一条规则继续适用:

  

允许的最大半径为50 000米。

因此,您的初始LatLng位置距离太远,如下图所示: tooFar http://i65.tinypic.com/18k8dd.png

所以附近的搜索无法访问它。 相反,如果您使用距离Nassau更近的中心进行查询,则按预期工作:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=25.0788005%2C-77.4699268&radius=50000&keyword=tiki%20bikini%20hut&key=YOUR_API_KEY

结果如下:inScope http://i68.tinypic.com/6ztvk5.jpg 结果显示在地图中:resultShown http://i65.tinypic.com/2ushr1s.jpg 正如您在JSON响应中看到的那样:

{
  "html_attributions":[

  ],
  "results":[
    {
      "address_components":[
        {
          "long_name":"Nassau",
          "short_name":"Nassau",
          "types":[
            "locality","political"
          ]
        },
        {
          "long_name":"New Providence",
          "short_name":"New Providence",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"Bahamas",
          "short_name":"BS",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"Nassau, Bahamas",
      "geometry":{
        "location":{
          "lat":25.0787957,"lng":-77.3493213
        }
      },
      "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
      "id":"ac8051aa71ba5159ac274abfd18f1ed669de6434",
      "name":"Tiki Bikini Hut",
      "photos":[
        {
          "height":3006,
          "html_attributions":[
            "Jude D'Souza"
          ],
          "photo_reference":"CoQBdwAAAMaD_AgEkLqigcklSzlAb9xpE2Vq8jBVolqarPSF17Z5KvJap4OrtQzIpuX_XpeZt0XQEF5dfh0kwfX-cn5VxIt7KmK3i5EzA6zhJeDSfP3qYEYSyMgyuzyzlmIoqBILXmlpKKSir43awBnp1AVgu_4jQ9hrVcik5gvy6RUIPrFnEhBEVXjUw02krxJiy0TGC1wnGhQtJuqhGJixxwczGnHkTqrdjTKUkA",
          "width":5344
        }
      ],
      "place_id":"ChIJPQxV1xt9L4kRIAd9AzuTmjQ",
      "reference":"CnRiAAAAqZmGFHqUBt3PWM3nouhli_jsPWlPt1SSvIv7Lltl6Hr-HVuMXdM5TI6-ksyHMrsIJgkKImNFojEidF9HGd_q0FA89l0TxmEBYWIW53Km5xhU0KXKXNQk4O7LZnwh5Qvs5QaLftI_AUC90443Lq84kBIQqAgc2yeqTjVFsd2JOkf55RoUNBA65tTK-S7lqWXmYlX5SbPi_Ek",
      "scope":"GOOGLE",
      "types":[
        "bar","restaurant","food","point_of_interest","establishment"
      ],
      "url":"https://maps.google.com/?cid=3790503918056572704",
      "vicinity":"Nassau"
    },
    {
      "address_components":[
        {
          "long_name":"Nassau Street",
          "short_name":"Nassau St",
          "types":[
            "route"
          ]
        },
        {
          "long_name":"Nassau",
          "short_name":"Nassau",
          "types":[
            "locality","political"
          ]
        },
        {
          "long_name":"New Providence",
          "short_name":"New Providence",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"Bahamas",
          "short_name":"BS",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"Nassau St, Nassau, Bahamas",
      "formatted_phone_number":"(242) 322-1514",
      "geometry":{
        "location":{
          "lat":25.0782201,"lng":-77.3501194
        }
      },
      "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png",
      "id":"a2397730559fc6850c1c3ac273e35847786e3ca6",
      "international_phone_number":"+1 242-322-1514",
      "name":"Nassau Junkanoo Beach Resort",
      "photos":[
        {
          "height":2097,
          "html_attributions":[
            "Kordian Witek"
          ],
          "photo_reference":"CoQBcwAAANk0iMSTxkpqkAGf2jTCLLwgRs-XLjxJJCuVFI6PDdjCK_29S7SxHDfGw2w9t0FXJS9RoSv61IqLYZ1uhF-Ei8mTFL2_350LegRreTUrUj5WsDG62__jhfhohO--2FENQfew9x4_Gk94KO_dgF0ootACEPz4ZbSJntUlbLnYfHlQEhBE-ul_zRlsNEndOGjPNueFGhQg6-tPWCDvePiJQXdeQe0DnM22xg",
          "width":4932
        }
      ],
      "place_id":"ChIJmZDMZhl9L4kR58vJmbsRXnU",
      "rating":4.5,
      "reference":"CnRvAAAAZvZhtQWqFBfYvtoVmZ-ANvTtkDK8vwTi9Mijl7TBIE72zXCh1SQA9M1xwicDmJsQhBtVDhkEAQcrQzpbFhMQEXHXajLnchXYW89l3v6_Ky-7PnDqEm7P9W3CWRmUe9ILb4ymzumZsVN3aAz1UyfRYhIQYAdXrIYNTKBX6MGi4MVrNBoUcrr4ojzxv9rktXdcHJ0we4xmw2I",
      "scope":"GOOGLE",
      "types":[
        "lodging","point_of_interest","establishment"
      ],
      "url":"https://maps.google.com/?cid=8457216647685065703",
      "vicinity":"Nassau Street, Nassau"
    }
  ],
  "status":"OK"
}