Skip to content

Instantly share code, notes, and snippets.

@tanishqvyas
Forked from coolaj86/google-to-bing-maps.js
Created April 21, 2020 08:34
Show Gist options
  • Save tanishqvyas/4170c8356fc229f6e970a173663837c7 to your computer and use it in GitHub Desktop.
Save tanishqvyas/4170c8356fc229f6e970a173663837c7 to your computer and use it in GitHub Desktop.
convert coords from google maps to bing maps
// 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);
/*
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&deg=0
*/
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