Skip to content

Instantly share code, notes, and snippets.

View mjaakko's full-sized avatar

Jaakko Malkki mjaakko

View GitHub Profile
@mjaakko
mjaakko / bbox2geohashes.js
Last active June 24, 2023 04:24
Converts a bounding box to geohashes
//Converts a bounding box bounded by minLat and maxLat and minLng and maxLng to a list of geohashes (e.g. ["60;24/19/84", "60;24/19/85"]) used for MQTT topic filters
function bbox2geohashes(minLat, minLng, maxLat, maxLng) {
var deltaLat = maxLat - minLat;
var deltaLng = maxLng - minLng;
var geohashLevel = Math.max(Math.ceil(Math.abs(Math.log10(deltaLat))), Math.ceil(Math.abs(Math.log10(deltaLng))));
var delta = Math.pow(10, -geohashLevel);
var geohashes = [];