我正在使用 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 接受location
和radius
以下查询在第二个结果中返回所需的地址:
关于google-maps - 具有位置偏差的 Google Places API 返回单个远距离结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55585801/