Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet Map API with Google Satellite Layer [duplicate]

I'm very interested in the Leaflet Map API.

However, I need to be able to use the Google Satellite Layer. I have not been able to find an example on how to add a Google Satellite Layer to Leaflet. I understand that I will still need to load the Google Maps API to do this (OpenLayers has an example).

like image 626
fnllc Avatar asked Feb 22 '12 11:02

fnllc


1 Answers

You don't need a plugin or the Google API, you can add it as a XYZ tile layer.

Streets

googleStreets = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{     maxZoom: 20,     subdomains:['mt0','mt1','mt2','mt3'] }); 

Hybrid:

googleHybrid = L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',{     maxZoom: 20,     subdomains:['mt0','mt1','mt2','mt3'] }); 

Satellite:

googleSat = L.tileLayer('http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{     maxZoom: 20,     subdomains:['mt0','mt1','mt2','mt3'] }); 

Terrain

googleTerrain = L.tileLayer('http://{s}.google.com/vt/lyrs=p&x={x}&y={y}&z={z}',{     maxZoom: 20,     subdomains:['mt0','mt1','mt2','mt3'] });   Note the difference in the "lyrs" parameter in the URL: Hybrid: s,h; Satellite: s; Streets: m; Terrain: p; 
like image 112
capie69 Avatar answered Sep 23 '22 12:09

capie69