3131 'z' : 31
3232 }
3333
34+
3435def decode_exactly (geohash ):
3536 """
3637 Decode the geohash to its exact values, including the error
@@ -45,7 +46,7 @@ def decode_exactly(geohash):
4546 for c in geohash :
4647 cd = __decodemap [c ]
4748 for mask in [16 , 8 , 4 , 2 , 1 ]:
48- if is_even : # adds longitude info
49+ if is_even : # adds longitude info
4950 lon_err /= 2
5051 if cd & mask :
5152 lon_interval = ((lon_interval [0 ]+ lon_interval [1 ])/ 2 , lon_interval [1 ])
@@ -62,6 +63,7 @@ def decode_exactly(geohash):
6263 lon = (lon_interval [0 ] + lon_interval [1 ]) / 2
6364 return lat , lon , lat_err , lon_err
6465
66+
6567def decode (geohash ):
6668 """
6769 Decode geohash, returning two strings with latitude and longitude
@@ -77,14 +79,15 @@ def decode(geohash):
7779 lons = lons .rstrip ('0' ) if "." in lons else lons
7880 return lats , lons
7981
82+
8083def encode (latitude , longitude , precision = 12 ):
8184 """
8285 Encode a position given in float arguments latitude, longitude to
8386 a geohash which will have the character count precision.
8487 """
8588 lat_interval , lon_interval = (- 90.0 , 90.0 ), (- 180.0 , 180.0 )
8689 geohash = []
87- bits = [ 16 , 8 , 4 , 2 , 1 ]
90+ bits = [16 , 8 , 4 , 2 , 1 ]
8891 bit = 0
8992 ch = 0
9093 even = True
0 commit comments