-
-
Save tanishqvyas/4170c8356fc229f6e970a173663837c7 to your computer and use it in GitHub Desktop.
convert coords from google maps to bing maps
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
// Believe it or not, Microsoft has this documented: | |
// http://msdn.microsoft.com/en-us/library/bb259689.aspx | |
function toBing(x, y, zoom) { | |
var x2 = pad(String(x.toString(2)), zoom + 1) | |
, y2 = pad(String(y.toString(2)), zoom + 1) | |
, quadkey = '' | |
; | |
function pad(n, p) { | |
while (n.length < p) { | |
n = '0' + n; | |
} | |
return n; | |
} | |
for (var i = 0; i < y2.length; i += 1) { | |
quadkey += (y2[i] + x2[i]); | |
} | |
// ensure that the number is positive (not two's complement) | |
quadkey = parseInt('0' + quadkey, 2); | |
// t0-t3 | |
return "http://ecn.t3.tiles.virtualearth.net/tiles/" | |
+ "a" | |
+ pad(quadkey.toString(4), zoom) | |
+ ".jpeg?g=915&mkt=en-us&n=z" | |
; | |
} | |
toBing(1555, 3095, 13); |
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
/* | |
Easy as pie | |
http://khm1.google.com/kh/v=108&src=app&x=24883&s=&y=49498&z=17&s=Gal | |
http://3.maptile.lbs.ovi.com/maptiler/v2/maptile/279af375be/satellite.day/17/24883/49498/256/jpg?lg=ENG&token=TrLJuXVK62IQk0vuXFzaig%3D%3D&requestid=yahoo.prod&app_id=eAdkWGYRoc4RfxVo0Z4B | |
*/ | |
// actually Nokia | |
function toYahoo(x, y, zoom) { | |
return "http://4.maptile.lbs.ovi.com/maptiler/v2/maptile/279af375be/satellite.day/" | |
+ zoom | |
+ "/" | |
+ x | |
+ "/" | |
+ y | |
+ "/256/jpg?lg=ENG&token=TrLJuXVK62IQk0vuXFzaig%3D%3D&requestid=yahoo.prod&app_id=eAdkWGYRoc4RfxVo0Z4B" | |
} | |
// png8 vs jpeg... why? | |
function toNokia(x, y, zoom) { | |
return "http://4.maptile.lbs.ovi.com/maptiler/v2/maptile/4176ef2b30/satellite.day/" | |
+ zoom | |
+ "/" | |
+ x | |
+ "/" | |
+ y | |
+ "/256/png8?token=fee2f2a877fd4a429f17207a57658582&appId=nokiaMaps" | |
} | |
toYahoo(24884, 49498, 17); | |
/* | |
At first I thought it wasn't working because I was using the 45º images, which have a different y scale: | |
http://khmdb1.google.com/kh?v=53&src=app&x=24883&s=&y=54195&z=17&s=Gali°=0 | |
*/ |
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
strategies.google = (function () { | |
var j = 0 | |
, galileos = [ | |
"G" | |
, "Ga" | |
, "Gal" | |
, "Gali" | |
, "Galil" | |
, "Galile" | |
, "Galileo" | |
] | |
, numServers = 2 | |
; | |
return function (tile, i) { | |
j = (i || j) % numServers; | |
return "http://khm" + (j % 2) + ".google.com/kh/" | |
+ "v=" | |
+ "108" | |
+ "&x=" | |
+ tile.x | |
+ "&y=" | |
+ tile.y | |
+ "&z=" | |
+ tile.zoom | |
+ "&s=" | |
+ galileos[j % galileos.length] | |
; | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment