I read the h3 doc and I am not sure finding the absolute distance between two geo point is one of the use case. There are formulas for it like in this page or google maps provides API for it. I see an h3 API for finding distance between hexagons but not sure how accurately or how to use it across different resolution etc. Any example or details are greatly appreciated. I hope using h3 I may reduce external API usages.
4 Answers
You are correct, there is no current H3 function to calculate the physical distance between two geographic points. We have a function internally in the library that will return the physical distance in kilometers, but we don't currently expose it in the H3 library API. There's an open request for this feature, and it's likely to be added in the next month or two.
Update: this is now available as h3.pointDist

- 55,314
- 10
- 149
- 165
Will below help?
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

- 289
- 2
- 10
There is an API at https://boundaries-io.com to obtain the Distance(miles) and Bearing of two H3 Addresses(Hex or Long value).
an example API call:
gives the below GeoJson results.
/rest/v1/public/boundary/h3/zipcode/index1/89283409857ffff/index2/89283446943ffff/hex?showLineBetween=true&showPoints=false
The service is free for 50 calls a day to give you some quick results,disclaimer I do work for this company

- 989
- 17
- 40
The point of h3 is to turn coordinates into hex ids; strings that you can perform exact matching on, not numbers you need to do complex calculations with.
For example, it is used when you want to find out if two locations are within X kilometers of one another. You would pick an appropriate resolution, find the h3index of both, then get the grid disk of one of those. If the other is in that list of ids, then it’s in a neighboring cell, so within X km.
It's faster and easier to calculate the distance between them using a simple algorithm if it’s a one-off or a few hundred. But if you need to compare distances of each location in a set of a million to the other locations in that set, that could take years to run that equation, depending on your system/database engine.
Here’s where h3 comes in. You run over your list one time, getting the index for each at different resolutions, and getting the neighbors of each resolution's index. Then you can get an exact string match of each location to every other one, using whichever location's resolution grid ids that you need for your desired distance.
Granted, the farther apart the points are, the less the accuracy will be, but that’s the point: you aren't going to take an Uber service from Toronto to Tijuana, but you might want to know who in that list of 100k people’s work addresses match by name and are under 10 miles from their home addresses which you already have in your database.

- 20,799
- 66
- 75
- 101

- 859
- 1
- 7
- 26