Skip to content

@crofty /index.html
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A example of using Google Map tiles with the Leaflet mapping library - http://matchingnotes.com/using-google-map-tiles-with-leaflet
<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script src="http://matchingnotes.com/javascripts/leaflet-google.js"></script>
</head>
<body>
<div style="width:500px; height:500px" id="map"></div>
<script type='text/javascript'>
var map = new L.Map('map', {center: new L.LatLng(51.51, -0.11), zoom: 9});
var googleLayer = new L.Google('ROADMAP');
map.addLayer(googleLayer);
</script>
</body>
</html>
@brak59

Awesome work Crofty! Very useful, worked like a dream.

@bencevans

Thanks Crofty! Just a heads up to anyone that may try this though, the google maps layer will appear above any other layers, change line 8 to use the url https://gist.github.com/raw/4504864/c9ef880071f959398b7cf0b687d4f37c352ea86d/leaflet-google.js to fix it :)

@viciousesque

Thanks Crofty. Map n00b. Totally did not understand why leafletjs wasn't creating map tiles. This worked, no problem, and illustrated interaction between leaflet and gMaps API.

Thanks!

@davidcalhoun

Note that this seems to have been written for Leaflet 0.4.5 (the previous stable version) and below. I get issues with the map freezing when trying to zoom with Leaflet 0.5.1 in place.

@abovethewater

Seems leaflet now requires the use of their CDN, so get 403 forbidden.

Simple fix in my fork (https://gist.github.com/abovethewater/5598094).

@cihadturhan

Hi,
Thanks for this nice plug-in.
Can anyone say me how can I use this for 0.4.5+ versions?
I can't even use it with 0.4.5. It makes map freeze too.

@RRSprinkhuizen

Doesn't work with current Leaflet version or dev version. Need the latest Leaflet for the draw plugin, so can't go back.

@tcql

Note, if you set zoomAnimation:false on the map object, it seems to behave, mostly. Although there's a bit of weirdness around zooming animation in general

@mmohando

thanks for this. does it involve cost? as we are using google maps?

@dhirajt

Cool +1

@justmytwospence

Very cool. When I zoom in/out, however, my overlay zooms about a full second before the google tiles zoom. Any idea what might be causing this or a simple fix?

@CodeZombieCH

I have the same problem as justmytwospence. It renders the Google layer implementation unusable :-/.

@fedegonzal

Hi Crofty, works for me.. but I need to add some overlays over google base tile and can't do it. Google's overall :S

@bmchild

Thanks for this. If anyone is interested in a demo here is a jsfiddle of the code above: http://jsfiddle.net/bL48E/

@lembitk

Good stuff. Got here via this answer on Stack Overflow. As also mentioned there, the official Leaflet plugins' page references a similar plugin by Pavel Shramov, which gives you access to Google tiles. Note how Pavel's repo contains also several other interesting Leaflet plugins, e.g there are also Bing and Yandex tiles available.

@emamut

What a great job, Crofty

@booherbg

Works great for me in leaflet 0.7.3 -- straight from the example.

@JatGitHub

Would love to see a snippet, or page URL

@malre

.

@Daggett-ua

Works good in last stable version. But there is available source for Leaflet 1.0 dev for working with Google Maps and Yandex Maps?

SOLUTION

Google, Yandex, Bing Maps Tiles for Leaflet 0.8 (on 1.0 works fine too)

@raghuxius

This example works good in Mozilla Firefox browser but when we try to use the IE or Chrome browser it throws an error at "var googleLayer = new L.Google('ROADMAP');" and it states that an object is expected here. Please can any one help in addressing this.

@r-barnes

Also having an issue with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.