首页 文章

Google Places API返回远离搜索中心的结果

提问于
浏览
1

这是一个我认为应该生成具有相同名称的酒店的查询非常接近参考点 .

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文本搜索会像那样呢?请注意,location参数指向酒店的确切位置 . 然而,我得到了5000公里以外的东西,除非我添加“酒店”这个词 .

谢谢

1 回答

  • 1

    这是相当古老的,但为了以防万一,我相信你应该使用 nearbysearch 而不是 textsearch . (在你的网址中)

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

    考虑到使用'nearby search,'位置和半径是必需参数 . 'textsearch'只需要 querykey .

    Note: Radius might be required not to be included if using rankby=distance. Check the documentation for more details.

    祝好运 .

相关问题