希望我能解释一下我的问题。
我正在使用Google的自动填充功能来获取目的地。一旦我有了目的地,我可以使用google的地方api来查找几何视口。但是视口是从北/东到南/西。我的问题是Elasticsearch geo_bbox从顶部/左侧到底部/右侧。见下面的例子。
Google Place API响应:
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Devon",
"short_name" : "Devon",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "England",
"short_name" : "England",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United Kingdom",
"short_name" : "GB",
"types" : [ "country", "political" ]
}
],
"adr_address" : "\u003cspan class=\"region\"\u003eDevon\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUK\u003c/span\u003e",
"formatted_address" : "Devon, UK",
"geometry" : {
"location" : {
"lat" : 50.77721349999999,
"lng" : -3.9994610
},
"viewport" : {
"northeast" : {
"lat" : 51.24619840,
"lng" : -2.88664060
},
"southwest" : {
"lat" : 50.20189620,
"lng" : -4.68065630
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "065fb13848aeae653fe25ee19d8a0a0289bd64dc",
"name" : "Devon",
"reference" : "CnRoAAAAN84gxrolBJLF_flpuwIyGum7pjln_KP9NJIHydIHMfbAo93nUdHSyYbv90GPUlW8Jx5D2ba-2fJHyzcHAdkZLkaJzSBEfj7dkR4NnBWzK9mFikZdyz3cee9IvOruHCZaicKfiXJP18jSfxXkvVv8gBIQrAopOdNbGQ6ovqEaEUqrxxoUaUYJEahZx7mTfJwEWOnxjTP3e9A",
"types" : [ "administrative_area_level_2", "political" ],
"url" : "https://maps.google.com/maps/place?q=Devon&ftid=0x486bf8abdac00247:0x12c6ba0cca9c58fd"
},
"status" : "OK"
}
弹性搜索示例
{
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_bounding_box" : {
"pin.location" : {
"top_left" : {
"lat" : 40.73,
"lon" : -74.1
},
"bottom_right" : {
"lat" : 40.717,
"lon" : -73.99
}
}
}
}
}
}
是否有更好的方法可以从谷歌获取更多信息,或者可以从备用角落进行弹性搜索。虽然文档没有说明这一点?
答案 0 :(得分:3)
哦,亲爱的,我有多厚。
我需要做的就是将结果换成弹性搜索。即,
{
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_bounding_box" : {
"pin.location" : {
"top_left" : {
"lat" : result.northeast.lat,
"lon" : result.southwest.lon
},
"bottom_right" : {
"lat" : result.southwest.lat,
"lon" : result.northwest.lon
}
}
}
}
}
}
答案 1 :(得分:0)
如果你知道东北角和西南角,你可以计算西北角(左上角)和东南角(右下角):
var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();
// calculated points
var NW = new google.maps.LatLng(NE.lat(), SW.lng());
var SE = new google.maps.LatLng(SW.lat(),NE.lng());