def geohash_encode(self, latitude, longitude, precision=6):
    base32 = '0123456789bcdefghjkmnpqrstuvwxyz'
    lat_interval = ((- 90.0), 90.0)
    lon_interval = ((- 180.0), 180.0)
    geohash = []
    bits = [16, 8, 4, 2, 1]
    bit = 0
    ch = 0
    even = True
    while (len(geohash) < precision):
        if even:
            mid = ((lon_interval[0] + lon_interval[1]) / 2)
            if (longitude > mid):
                ch |= bits[bit]
                lon_interval = (mid, lon_interval[1])
            else:
                lon_interval = (lon_interval[0], mid)
        else:
            mid = ((lat_interval[0] + lat_interval[1]) / 2)
            if (latitude > mid):
                ch |= bits[bit]
                lat_interval = (mid, lat_interval[1])
            else:
                lat_interval = (lat_interval[0], mid)
        even = (not even)
        if (bit < 4):
            bit += 1
        else:
            geohash += base32[ch]
            bit = 0
            ch = 0
    return ''.join(geohash)
def geohash_encode(self, latitude, longitude, precision=6):
    base32 = '0123456789bcdefghjkmnpqrstuvwxyz'
    lat_interval = ((- 90.0), 90.0)
    lon_interval = ((- 180.0), 180.0)
    geohash = []
    bits = [16, 8, 4, 2, 1]
    bit = 0
    ch = 0
    even = True
    while (len(geohash) < precision):
        if even:
            mid = ((lon_interval[0] + lon_interval[1]) / 2)
            if (longitude > mid):
                ch |= bits[bit]
                lon_interval = (mid, lon_interval[1])
            else:
                lon_interval = (lon_interval[0], mid)
        else:
            mid = ((lat_interval[0] + lat_interval[1]) / 2)
            if (latitude > mid):
                ch |= bits[bit]
                lat_interval = (mid, lat_interval[1])
            else:
                lat_interval = (lat_interval[0], mid)
        even = (not even)
        if (bit < 4):
            bit += 1
        else:
            geohash += base32[ch]
            bit = 0
            ch = 0
    return .join(geohash)