Last active
March 9, 2024 18:17
-
-
Save tuket/1bc37ee7566d4af3ae14fb4ccbaed083 to your computer and use it in GitHub Desktop.
Google Maps: Get tile image from latlong coordinate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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