import math


def latlng2tile_google(lat_deg, lng_deg, z):
    """
    convert latitude, longitude and zoom into tile in x and y axis
    referencing http://www.cnblogs.com/Tangf/archive/2012/04/07/2435545.html and https://blog.csdn.net/mygisforum/article/details/7582449
    :param lat_deg: latitude in degree
    :param lng_deg: longitude in degree
    :param z:       map scale (0-18)
    :return:        Return two parameters as tile numbers in x axis and y axis
    """
    if lat_deg >= 85.05112877980659 or lat_deg <= -85.05112877980659:
        raise ValueError('wmts latitude error lat')
    lat_rad = math.radians(lat_deg)
    n = 2.0 ** z
    x = ((lng_deg + 180.0) / 360.0 * n)
    y = ((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
    return x, y