google-maps - 具有位置偏差的 Google Places API 返回单个远距离结果

标签 google-maps google-places-api

我正在使用 Google Maps API 来帮助进行位置搜索,但出乎意料的是,对于非常一般的搜索,我得到了一个遥远的结果。因此,由于 locationbias,我转而使用 Google Places API,但现在 Google Places 似乎只返回一个位置,并且不使用位置偏差将位置缩小到给定的纬度和经度半径。

例子:

Text Search = "123 Main St"
Circle Radius = 16000 meters (10 miles)
Lat/Long = 41.761898,-72.674596 (Hartford, Connecticut)

https://maps.googleapis.com/maps/api/place/textsearch/json?inputtype=textquery&key=[KEY]&locationbias=circle:16000@41.761898,-72.674596&query=123+Main+St

结果:

"123 Main St, San Francisco, California"

{
   "html_attributions" : [],
   "results" : [
      {
         "formatted_address" : "123 Main St, San Francisco, CA 94105, USA",
         "geometry" : {
            "location" : {
           "lat" : 37.7917688,
                   "lng" : -122.3944272
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 37.79301167989272,
                  "lng" : -122.3931579701073
               },
               "southwest" : {
                  "lat" : 37.79031202010728,
                  "lng" : -122.3958576298927
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "596b2040c5c04babad99f2c1adcba7e943324bbb",
         "name" : "123 Main St",
         "place_id" : "ChIJZRkIYGSAhYARyXebnnhvMC0",
         "plus_code" : {
            "compound_code" : "QJR4+P6 SoMa, San Francisco, CA, USA",
            "global_code" : "849VQJR4+P6"
         },
         "reference" : "ChIJZRkIYGSAhYARyXebnnhvMC0",
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

我希望它返回一个关于locationbias 的结果(123 Main St, Hartford Connecticut),或者返回许多结果,从离康涅狄格州哈特福德最近的地方开始。

那么 Google Places API 如何与 locationbias 一起使用以返回预期结果?或者如何将某种类型的位置偏差添加到 Google Maps API。

最佳答案

只是回答这个问题(注意到 OP 的评论):

textquery 接受locationradius

以下查询在第二个结果中返回所需的地址:

https://maps.googleapis.com/maps/api/place/textsearch/json?inputtype=textquery&key=API_KEY&location=41.761898,-72.674596&radius=16000&query=123+Main+St

关于google-maps - 具有位置偏差的 Google Places API 返回单个远距离结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55585801/

相关文章:

google-maps - 在 Google Maps API v3 中使用标记和折线(包括自动居中和自动缩放)

internet-explorer - Google Maps V3 自定义标记未在 IE 中显示

javascript - 如何从地址获取纬度和经度并将其传递给 react 传单?

android - INSTALL_FAILED_MISSING_SHARED_LIBRARY

java - 如何在没有双重请求的情况下使用 Google Places API 获取特定类型的 Lat Longs 列表?

javascript - 如何从自定义组件获取状态值到另一个父组件

jquery - 谷歌地图 : How to rotate `groundoverlay` need trick

循环内的 Javascript Promise.all()

google-maps - 该 IP、站点或移动应用程序无权使用该 IP 授权的 API key

android - Places Api 在 android 中停止工作