greenwich/tile.py
def to_tile(lon, lat, zoom):
    """Returns a tuple of (xtile, ytile) from a (longitude, latitude) coordinate.

    See http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

    Arguments:
    lon - longitude as int or float
    lat - latitude as int or float
    zoom - zoom level as int or float
    """
    lat_rad = math.radians(lat)
    n = 2.0 ** zoom
    xtile = int((lon + 180.0) / 360.0 * n)
    ytile = int((1.0 - math.log(math.tan(lat_rad) +
                (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
    return xtile, ytile
def to_tile(lon, lat, zoom):
    """Returns a tuple of (xtile, ytile) from a (longitude, latitude) coordinate.

    See http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

    Arguments:
    lon - longitude as int or float
    lat - latitude as int or float
    zoom - zoom level as int or float
    """
    lat_rad = math.radians(lat)
    n = 2.0 ** zoom
    xtile = int((lon + 180.0) / 360.0 * n)
    ytile = int((1.0 - math.log(math.tan(lat_rad) +
                (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
    return xtile, ytile
Returns a tuple of (xtile, ytile) from a (longitude, latitude) coordinate.

    See http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

    Arguments:
    lon - longitude as int or float
    lat - latitude as int or float
    zoom - zoom level as int or float