Files
mobilizon-frontend/src/utils/location.ts
Thomas Citharel 2e72f6faf4 build: switch from yarn to npm to manage js dependencies and move js contents to root
yarn v1 is being deprecated and starts to have some issues

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2023-11-14 17:24:42 +01: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;
};