import math


def get_xy(lat, lng, zoom):
    """
        Generates an X,Y tile coordinate based on the latitude, longitude
        and zoom level
        Returns:    An X,Y tile coordinate
    """

    tile_size = 256
    # Use a left shift to get the power of 2
    # i.e. a zoom level of 2 will have 2^2 = 4 tiles
    num_tiles = 1 << zoom

    # Find the x_point given the longitude
    point_x = (tile_size / 2 + lng * tile_size / 360.0) * num_tiles // tile_size

    # Convert the latitude to radians and take the sine
    sin_y = math.sin(lat * (math.pi / 180.0))

    # Calculate the y coordinate
    point_y = ((tile_size / 2) + 0.5 * math.log((1 + sin_y) / (1 - sin_y)) *
               - (tile_size / (2 * math.pi))) * num_tiles // tile_size

    return int(point_x), int(point_y)