2

希望我能解释我的问题。

我正在使用 Google 的自动完成功能来获取人员目的地。一旦我有了目的地,我就可以使用谷歌的 place 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
                    }
                }
            }
        }
    }
}

有没有更好的方法从谷歌获取更多信息,或者弹性搜索可以从其他角落工作。虽然文档没有这么说?

4

2 回答 2

3

哦,天哪,我有多厚。

我需要做的就是将结果换成我的弹性搜索。IE,

{
    "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
                    }
                }
            }
        }
    }
}
于 2013-01-10T22:13:13.050 回答
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());
于 2013-01-10T15:47:44.003 回答