JavadocMD / simplelatlng

A simple, lightweight library for common latitude and longitude calculation needs in Java.
90 stars 20 forks source link

Geohasher.decode yields incorrect results for many 12-character geohashes #18

Open JavadocMD opened 2 years ago

JavadocMD commented 2 years ago

Due to LatLng's 6-digit fixed precision, certain 12-character geohashes will be decoded and then improperly rounded to produce a latitude/longitude value that is incorrect by the geohash specification. This happens for the majority of all possible 12-character geohashes. The magnitude of the error in each case is within one-millionth of a degree latitude and/or longitude. However this also causes SimpleLatLng's geohashing implementation to exhibit instability during round-trips.

Example:

String a = "s00000j202n8";
LatLng x = Geohasher.decode(a); // x = LatLng(0.000000,0.007229)
String b = Geohasher.hash(x); // b = "s00000j202n2"
// s00000j202n8 != s00000j202n2
JavadocMD commented 2 years ago

A full write-up of my investigation into this issue is available on the wiki.