import math


def latlon2tms(lat,lon,zoom):
    """
    Converts lat/lon (in degrees) to tile x/y coordinates in the given zoomlevel.
    Note that it doesn't give integers! If you need integers, truncate
    the result yourself.
    """
    n = 2**zoom
    lat_rad = math.radians(lat)
    xtile = (lon+ 180.0) / 360.0 * n
    ytile = (1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n
    return (xtile, ytile)