Skip to content

Instantly share code, notes, and snippets.

@tuket
Last active March 9, 2024 18:17
Show Gist options
  • Save tuket/1bc37ee7566d4af3ae14fb4ccbaed083 to your computer and use it in GitHub Desktop.
Save tuket/1bc37ee7566d4af3ae14fb4ccbaed083 to your computer and use it in GitHub Desktop.
Google Maps: Get tile image from latlong coordinate
import math
def latlongToTile(latlongDegs, zoom):
n = 2 ** zoom
latRads = math.radians(latlongDegs[0])
tileX = n * ((latlongDegs[1] + 180.0) / 360.0)
tileY = n * (1.0 - (math.log(math.tan(latRads) + 1.0/math.cos(latRads)) / math.pi)) / 2.0
return (int(tileX), int(tileY))
def latlongToUrl(latlongDegs, zoom):
ll = latlongToTile(latlongDegs, zoom)
url = "http://mt1.google.com/vt/lyrs=y&x=%d&y=%d&z=%d" % (ll[0], ll[1], zoom)
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment