Elasticsearch - 有没有办法将地理边界框与距离结合起来
Elasticsearch -Is there a way I can combine geo bounding box with distance
有什么方法可以将地理边界框 (https://bonsai.io/blog/efficient-sorting-of-geo-distances-in-elasticsearch) 与 distance.Basically 相结合 我想获取 100 公里地理边界框内的数据。即 top_left lat/long 距离中心 lat/long 50 公里,bottom_right.
也是如此
这个有帮助。
https://zaemis.blogspot.com/2011/01/geolocation-search.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Geo location</title>
</head>
<body>
<pre id="geolocation"></pre>
</body>
<script>
const currentLocation = {
lat: 10.7904833, //Tiruchirapalli, Tamilnadu
lng : 78.7046725 //Tiruchirapalli, Tamilnadu
}
const distance = 31; // In miles (31 mile equal to 50km)
function degToRad(d){
return d * (Math.PI/180);
}
function radToDeg(r){
return r * (180/Math.PI);
}
function destination(lat,lon, bearing, distance) {
const radius = 3963.19;
const rLat = degToRad(lat);
const rLon = degToRad(lon);
const rBearing = degToRad(bearing);
const rAngDist = distance / radius;
const rLatB = Math.asin(Math.sin(rLat) * Math.cos(rAngDist) + Math.cos(rLat) * Math.sin(rAngDist) * Math.cos(rBearing));
const rLonB = rLon + Math.atan2(Math.sin(rBearing) * Math.sin(rAngDist) * Math.cos(rLat), Math.cos(rAngDist) - Math.sin(rLat) * Math.sin(rLatB));
return {
lat : radToDeg(rLatB),
lng : radToDeg(rLonB)
}
};
/**
* Call destination funtion
* @param {latitude,longitude,degree,distance in miles}
*/
const boundaries = [{
topLeft : destination(currentLocation.lat,currentLocation.lng,315,31),
bottomRight : destination(currentLocation.lat,currentLocation.lng,135,31)
}];
document.getElementById("geolocation").innerHTML = JSON.stringify(boundaries[0],undefined,2);
</script>
</html>
有什么方法可以将地理边界框 (https://bonsai.io/blog/efficient-sorting-of-geo-distances-in-elasticsearch) 与 distance.Basically 相结合 我想获取 100 公里地理边界框内的数据。即 top_left lat/long 距离中心 lat/long 50 公里,bottom_right.
也是如此这个有帮助。 https://zaemis.blogspot.com/2011/01/geolocation-search.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Geo location</title>
</head>
<body>
<pre id="geolocation"></pre>
</body>
<script>
const currentLocation = {
lat: 10.7904833, //Tiruchirapalli, Tamilnadu
lng : 78.7046725 //Tiruchirapalli, Tamilnadu
}
const distance = 31; // In miles (31 mile equal to 50km)
function degToRad(d){
return d * (Math.PI/180);
}
function radToDeg(r){
return r * (180/Math.PI);
}
function destination(lat,lon, bearing, distance) {
const radius = 3963.19;
const rLat = degToRad(lat);
const rLon = degToRad(lon);
const rBearing = degToRad(bearing);
const rAngDist = distance / radius;
const rLatB = Math.asin(Math.sin(rLat) * Math.cos(rAngDist) + Math.cos(rLat) * Math.sin(rAngDist) * Math.cos(rBearing));
const rLonB = rLon + Math.atan2(Math.sin(rBearing) * Math.sin(rAngDist) * Math.cos(rLat), Math.cos(rAngDist) - Math.sin(rLat) * Math.sin(rLatB));
return {
lat : radToDeg(rLatB),
lng : radToDeg(rLonB)
}
};
/**
* Call destination funtion
* @param {latitude,longitude,degree,distance in miles}
*/
const boundaries = [{
topLeft : destination(currentLocation.lat,currentLocation.lng,315,31),
bottomRight : destination(currentLocation.lat,currentLocation.lng,135,31)
}];
document.getElementById("geolocation").innerHTML = JSON.stringify(boundaries[0],undefined,2);
</script>
</html>