[GIS] Creating a Bing and Google Tile Layer for Leaflet

javascriptleaflet

I want to use the Leaflet Javascript Library to display both a Google and Bing Tile Layer, though I'm unsure how to construct the url. The documentation shows an example using OSM:

var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/YOUR-API-KEY/997/256/{z}/{x}/{y}.png',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18});

But for some reason I can't duplicate this for either Bing or Google. Any ideas?

Thanks.

Best Answer

Google Maps

Google Maps forbids such uses. The only allowed access to their content is through their Maps API (see section 10.1 of the ToS).

Bing Maps Web Services

Bing Maps is the only commercial provider I know that allows such uses, through their Web Services feature. You will need an API key, though.

Bing will be a bit annoying to get, since they use quadkeys (an unique index for each tile) instead of {x,y} coordinates (good comparison there). You'll therefore need to create a new L.ILayer implementation that conforms to this URL scheme.

Since you're of course not the first one to have this request  ;)  , some others have already coded such implementations. One is a pending pull request to the Leaflet repo, the other is directly available as a Gist. Try whichever you prefer, and add your weight to the pull request to make it merged faster  :)

Related Question