-
-
Save stellarpower/bd31a8d6c5f64307931b385af755fe73 to your computer and use it in GitHub Desktop.
Downloads and stitches map tiles
This file contains hidden or 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
// For a given latitude, longitude, and zoom, returns the URL to an image for that tile. | |
function tileIndex(latitude, longitude, zoom){ | |
if ((latitude === undefined) || (longitude === undefined) || (zoom === undefined)) | |
throw("Arguments mising in tileIndex"); | |
var lat_rad = latitude / 180 * Math.PI; | |
var n = 1 << zoom; | |
var xtile = n * ((longitude + 180) / 360); | |
var ytile = n * (1 - (Math.log (Math.tan (lat_rad) + 1/Math.cos (lat_rad)) / Math.PI)) / 2; | |
return [Math.floor(xtile), Math.floor(ytile)] | |
} | |
function satelliteImage(latitude, longitude, zoom){ | |
const Server = 'khms2' | |
const Version = 923 | |
var [x, y] = tileIndex(latitude, longitude, zoom) | |
return 'https://' + Server + '.google.com/kh/v=' + Version + '?x=' + x + '&y=' + y + '&z=' + zoom | |
} | |
// Test: satelliteImage(51.4733514399, -0.00088499646, 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment