mobilizon.chapril.org-mobil.../js/src/utils/location.ts
Thomas Citharel ee20e03cc2
Migrate to Vue 3 and Vite
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2022-08-11 16:46:31 +02:00

23 lines
649 B
TypeScript

import ngeohash from "ngeohash";
const GEOHASH_DEPTH = 9; // put enough accuracy, radius will be used anyway
export const coordsToGeoHash = (
lat: number | undefined,
lon: number | undefined,
depth = GEOHASH_DEPTH
): string | undefined => {
if (lat && lon && depth) {
return ngeohash.encode(lat, lon, GEOHASH_DEPTH);
}
return undefined;
};
export const geoHashToCoords = (
geohash: string | undefined
): { latitude: number; longitude: number } | undefined => {
if (!geohash) return undefined;
const { latitude, longitude } = ngeohash.decode(geohash);
return latitude && longitude ? { latitude, longitude } : undefined;
};