def latlontopixels(lat, lon, zoom): import urllib from io import StringIO from PIL import Image from math import log, exp, tan, atan, pi, ceil EARTH_RADIUS = 6378137 EQUATOR_CIRCUMFERENCE = 2 * pi * EARTH_RADIUS INITIAL_RESOLUTION = EQUATOR_CIRCUMFERENCE / 256.0 ORIGIN_SHIFT = EQUATOR_CIRCUMFERENCE / 2.0 mx = (lon * ORIGIN_SHIFT) / 180.0 my = log(tan((90 + lat) * pi/360.0))/(pi/180.0) my = (my * ORIGIN_SHIFT) /180.0 res = INITIAL_RESOLUTION / (2**zoom) px = (mx + ORIGIN_SHIFT) / res py = (my + ORIGIN_SHIFT) / res print('px'+str(px)) print('py'+str(py)) return px, py