import { S2Cell , S2LatLng } from "nodes2ts" ; import { GeoPoint } from "../types" ; import * as Long from "long" ; export class S2Manager { static generateGeohash ( geoPoint ) { const latLng = S2LatLng . fromDegrees ( geoPoint . latitude , geoPoint . longitude ) ; const cell = S2Cell . fromLatLng ( latLng ) ; const cellId = cell . id ; return cellId . id ; } public static generateHashKey ( geohash , hashKeyLength ) { if ( geohash . lessThan ( 0 ) ) { hashKeyLength ++ ; } const geohashString = geohash . toString ( 10 ) ; const denominator = Math . pow ( 10 , geohashString . length - hashKeyLength ) ; return geohash . divide ( denominator ) ; } }