convertToGeohash function

String convertToGeohash(
  1. dynamic y,
  2. dynamic x,
  3. dynamic latitude,
  4. dynamic longitude,
  5. int precision,
)

Convert location point to geohash taking into account Earth curvature

Implementation

String convertToGeohash(y, x, latitude, longitude, int precision) {
  double pi = 3.14159265359;

  double rEarth = 6371000;

  double? latDiff = (y / rEarth) * (180 / pi);
  double? lonDiff = (x / rEarth) * (180 / pi) / cos(latitude * pi / 180);

  double finalLat = latitude + latDiff;
  double finalLon = longitude + lonDiff;

  return geoHasher.encode(finalLon, finalLat, precision: precision);
}