public class Geohasher extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
Geohasher.BitStore
Specialization of BitSet to actually keep track of
the number of bits that are being usefully employed, regardless
of whether or not they are 1 or 0.
|
| Modifier and Type | Field and Description |
|---|---|
protected static BigDecimal[] |
LAT_BIT_VALUES |
protected static BigDecimal[] |
LNG_BIT_VALUES |
static int |
PRECISION
Number of hash characters supported.
|
| Constructor and Description |
|---|
Geohasher() |
| Modifier and Type | Method and Description |
|---|---|
protected static double |
bitsToDouble(BitSet bits,
BigDecimal[] bitValues)
Converts the set of bits representing a single value to double.
|
protected static String |
bitsToHash(BitSet bits)
Encodes an interleaved set of bits to its base-32 geohash.
|
static LatLng |
decode(String hash)
Decodes a geohash string to its LatLng equivalent.
|
protected static BitSet[] |
deInterleave(BitSet bits)
De-interleaves a series of bits.
|
protected static BitSet |
doubleToBits(double value,
double maxRange)
Converts a double value to its bit representation in the geohash
specification.
|
static String |
hash(LatLng point)
Geohashes a latitude and longitude.
|
protected static BitSet |
hashToBits(String hash)
Converts a hash string into a series of bits.
|
protected static BitSet |
interleave(BitSet evenBits,
BitSet oddBits)
Interleaves two sets of bits.
|
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))
protected static final BigDecimal[] LAT_BIT_VALUES
protected static final BigDecimal[] LNG_BIT_VALUES
public static LatLng decode(String hash)
hash - the geohash string of any precision, although LatLng will
still not become more precise than its settings.protected static BitSet hashToBits(String hash)
hash - the geohash string.protected static BitSet[] deInterleave(BitSet bits)
bits - the bits to de-interleave.protected static double bitsToDouble(BitSet bits, BigDecimal[] bitValues)
bits - the bits for this value.bitValues - the correct set of pre-computed bit-values to use
for the particular value we are decoding: latitude or longitude.public static String hash(LatLng point)
point - the point to hash.PRECISION.protected static String bitsToHash(BitSet bits)
bits - the set of bits to encode.protected static BitSet interleave(BitSet evenBits, BitSet oddBits)
evenBits - the bits to use for even bits. (0, 2, 4,...)oddBits - the bits to use for odd bits. (1, 3, 5,...)protected static BitSet doubleToBits(double value, double maxRange)
value - the value to encode.maxRange - the max range for the particular value we are
encoding: latitude = 90.0, longitude = 180.0.Copyright © 2010-2015. All Rights Reserved.