def pixelstolatlon(px, py, 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 res = INITIAL_RESOLUTION / (2**zoom) mx = px * res - ORIGIN_SHIFT my = py * res - ORIGIN_SHIFT lat = (my / ORIGIN_SHIFT) * 180.0 lat = 180 / pi * (2*atan(exp(lat*pi/180.0)) - pi/2.0) lon = (mx / ORIGIN_SHIFT) * 180.0 print('lat'+str(lat)) print('lon'+str(lon)) return lat, lon