【问题标题】:Google Places API Returns a result far away from the search centerGoogle Places API 返回远离搜索中心的结果
【发布时间】:2013-04-25 11:54:39
【问题描述】:

我认为这是一个查询,它应该生成与参考点非常接近的同名酒店。

https://maps.googleapis.com/maps/api/place/textsearch/xml?key=_your_api_key_goes_in_here_&sensor=false&language=en&location=56.1995,-4.746&radius=30000&query=ARROCHAR

您可以看到位置是 56.1995,-4.746。这是英国的一个地方。查询是否为名为 Arrochar 的酒店。酒店确实存在。结果如下所示:

{
   "html_attributions" : [],
   "results" : [
      {
         "formatted_address" : "Arrochar, Staten Island, NY, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.59234250,
               "lng" : -74.07407289999999
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 40.60012790,
                  "lng" : -74.05918419999999
               },
               "southwest" : {
                  "lat" : 40.5779020,
                  "lng" : -74.08570610
               }
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "c7d9f74dca8676759bfe7ea168b8547cd6de3c5e",
         "name" : "Arrochar",
         "reference" : "CpQBiAAAAKYklx4_uV5ovlJP-x-fGr2VAqzhUCRQ2icNBXj2b5TkGZMqix3tL4xyTizwa0_UdZ5VDbI3psEagu0tTiFc2N6Awn2OJE4Oc3NXtXyaUlADLhJKwnZSuMFLFv85ia3AKiR9fFVWH96u6lEcC16foKMyFREY_KR6Z97QdShfiJCPYNlYZye49gsdU0UsIx3YbxIQa5LUZiMGZvW8sQHn_Cog-hoUr4bMXlYdo9Xae82ZRL-BEDSKRAw",
         "types" : [ "neighborhood", "political" ]
      }
   ],
   "status" : "OK"
}

可以看到,这个地方在美国,距离 5000 多公里。现在,如果有人去修改查询,看起来也像这样:

https://maps.googleapis.com/maps/api/place/textsearch/xml?key=_your_api_key_goes_in_here_&sensor=false&language=en&location=56.1995,-4.746&radius=30000&query=hotel+ARROCHAR

然后出现正确的结果:

{
   "formatted_address" : "Main Street, Arrochar, United Kingdom",
   "geometry" : {
      "location" : {
         "lat" : 56.199560,
         "lng" : -4.7459760
      }
   },
   "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png",
   "id" : "78d53766dfb2c3bb6008301b079423fffb78b801",
   "name" : "Arrochar Hotel",
   "reference" : "CnRtAAAAJPg2ABkegIT9Q12hABjfGezwGgHCc3ur1W761rhtkQq0n6Id-cgaLREU-g8Uo5Bnw4ovaAnqCrYm_fHEKjBHOrHK5dvcGpAndQVsl-zi_qZSZR6Sa5HvYZI4pA3ne3rNTl0m4TwuwmMM0nx2gSkxEBIQFqgW85GrUZI8SQFvohgMiBoU51C716M4m-ySUVECgT4BFZUYB50",
   "types" : [ "lodging", "establishment" ]
}

那么为什么 Places API 文本搜索会这样呢?请注意,位置参数指向酒店所在的确切位置。然而,我得到的东西是 5000 公里外的东西,除非我加上“酒店”这个词。

谢谢

【问题讨论】:

    标签: google-places-api


    【解决方案1】:

    这已经很老了,但以防万一,我相信你应该使用nearbysearch 而不是textsearch。 (在您的网址中)

    根据 Google Places API 文档,您的搜索与特定位置/距离无关。

    考虑到使用“附近搜索”时,位置和半径是必需的参数。 'textsearch' 只需要querykey

    注意:如果使用rankby=distance,可能需要不包括半径。 Check the documentation 了解更多详情。

    祝你好运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多