[erlang-questions] Debugging float math in geohashing module

Gustavo Niemeyer gustavo@REDACTED
Wed Jun 4 05:44:36 CEST 2008


Hi Nick,

(...)
> The decode functionality is different however. When I attempt to decode a
> geohash into a latitude/longitude pair the end result is slightly* off. When
(...)

Can you present an example of what you'd expect to happen, and what's
actually happening?

If I understand what you mean, there might be nothing wrong with your code.
Note that due to the nature of the Geohash algorithm itself, in most cases
you won't be able to decode the value into a precise decimal floating
point.

What is done by the software behind geohash.org during encoding is to
compute how many bits you need to at least match the decimal precision
given as input, and during decoding the inverse is done: it only shows
the decimal digits it can correctly represent given the number of bits
available.

As a hint, if you have 8 bits for the longitude code, and a maximum value
of 360, the maximum error is 360 / 2^8, and with log(maximum_error, 10)
you get the decimal exponent of the maximum error, which is pretty close
to what you want.

-- 
Gustavo Niemeyer
http://niemeyer.net



More information about the erlang-questions mailing list