Uber h3 用于查找两个地理位置之间的距离

Uber h3 for finding distance between two geo locations

我阅读了 h3 文档,我不确定找到两个地理点之间的绝对距离是用例之一。在 this page or google maps provides API for it. I see an h3 API 中有用于查找六边形之间距离的公式,但不确定如何准确或如何在不同分辨率下使用它等。非常感谢任何示例或细节。我希望使用 h3 可以减少外部 API 的使用。

你是对的,目前H3没有函数可以计算两个地理点之间的物理距离。我们在库中有一个内部函数,可以 return 以公里为单位的物理距离,但我们目前没有在 H3 库中公开它 API。有一个空缺 request for this feature,可能会在接下来的一两个月内添加。

更新:现在可用 h3.pointDist

下面有帮助吗?

const h3 = require("h3-js");

function distanceBetweenIndexCentres(h3Index1, h3Index2){
    if(!h3.h3IsValid(h3Index1) || !h3.h3IsValid(h3Index2))
        throw 'invalid h3 indexes provided'

    let index1CenterCoordinates = h3.h3ToGeo(h3Index1);
    let index2CenterCoordinates = h3.h3ToGeo(h3Index2);

    return distanceInKm(index1CenterCoordinates[0], index1CenterCoordinates[1], index2CenterCoordinates[0], index2CenterCoordinates[1])
}

function distanceInKm(lat1, lon1, lat2, lon2) {
    if ((lat1 == lat2) && (lon1 == lon2)) {
        return 0;
    }
    else {
        var radlat1 = Math.PI * lat1/180;
        var radlat2 = Math.PI * lat2/180;
        var theta = lon1-lon2;
        var radtheta = Math.PI * theta/180;
        var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
        if (dist > 1) {
            dist = 1;
        }
        dist = Math.acos(dist);
        dist = dist * 180/Math.PI;
        dist = dist * 60 * 1.1515;
        return dist * 1.609344;
    }
}


let h3Index1 = h3.geoToH3(16.750642, 78.017239, 7);
let h3Index2 = h3.geoToH3(16.806983, 78.027875, 6);
console.log('distance in km: '+distanceBetweenIndexCentres(h3Index1, h3Index2))

//prints - distance in km: 7.60193311570551

https://boundaries-io.com处有一个API获取两个H3地址(Hex或Long值)的距离(英里)和方位。
API 调用示例: 给出以下 GeoJson 结果。

   /rest/v1/public/boundary/h3/zipcode/index1/89283409857ffff/index2/89283446943ffff/hex?showLineBetween=true&showPoints=false

这项服务是免费的,每天拨打 50 次电话给您一些快速的结果,免责声明我在这家公司工作