com.javadocmd.simplelatlng
Class Geohasher

java.lang.Object
  extended by com.javadocmd.simplelatlng.Geohasher

public class Geohasher
extends Object

Implements the Geohash algorithm for hashing latitude and longitude points. Note: this implementation is only "stable" with 12-character hashes. Decoding "s" and re-hashing the result yields "t40000000000". Decoding and re-hashing "t40000000000" yields the same. 12 characters was chosen because this gives us precision up to one-millionth of a degree, like the rest of this library.

Author:
Tyler Coles

Field Summary
static int PRECISION
          Number of hash characters supported.
 
Constructor Summary
Geohasher()
           
 
Method Summary
static LatLng decode(String hash)
          Decodes a geohash string to its LatLng equivalent.
static String hash(LatLng point)
          Geohashes a latitude and longitude.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRECISION

public static final int PRECISION

Number of hash characters supported.

Translates to binary bits per value by the formula:
BITS = ((PRECISION * 5) / 2) + PRECISION % 2.

BITS in turn translates to numerical precision by the formula:
LATITUDE_ERROR = 90.0 / (2 ^ (BITS + 1))
LONGITUDE_ERROR = 180.0 / (2 ^ (BITS + 1))

See Also:
Constant Field Values
Constructor Detail

Geohasher

public Geohasher()
Method Detail

decode

public static LatLng decode(String hash)
Decodes a geohash string to its LatLng equivalent.

Parameters:
hash - the geohash string of any precision, although LatLng will still not become more precise than its settings.
Returns:
the decoded point.

hash

public static String hash(LatLng point)
Geohashes a latitude and longitude.

Parameters:
point - the point to hash.
Returns:
the hash string to the set character precision: PRECISION.


Copyright © 2010-2013. All Rights Reserved.