'Returns the optimal Zoom level for the given geometry.'

def get_zoom(self, geom):

    if ((not isinstance(geom, GEOSGeometry)) or (geom.srid != 4326)):
        raise TypeError('get_zoom()    expects    a    GEOS    Geometry    with    an    SRID    of    4326.')
    env = geom.envelope
    (env_w, env_h) = self.get_width_height(env.extent)
    center = env.centroid
    for z in xrange(self._nzoom):
        (tile_w, tile_h) = self.get_width_height(self.tile(center, z).extent)
        if ((env_w > tile_w) or (env_h > tile_h)):
            if (z == 0):
                raise GoogleMapException('Geometry    width    and    height    should    not    exceed    that    of    the    Earth.')
            return (z - 1)
    return (self._nzoom - 1)
