4

I have a problem using the markers with Google Maps with Leaflet. In this example you can see the difference between Google Maps or OSM.

Using OSM, the marker moves with the map but when using Google Maps, it seems that the movement is not synchronized.

Another example of the same problem

Is there any known solution to this issue?

4

What you are describing is a well known issue with animation of Google basemap tiles in Leaflet, and unfortunately, I don't think there is an easy solution.

The map in the fiddle uses the Leaflet Google.js plugin by Pavel Shramov.

As explained in this answer by @mourner, this plugin "acts as a proxy to the original Google Maps API v3, so it doesn't work as smoothly as simple Leaflet tile layers, and unfortunately you can't use Google Maps tiles directly [in Leaflet] because of Terms of Use restrictions"

You could try the alternatives discussed here, but I think you will have the same problems with animation that you have now (looks very similar to the Shramov plugin).

1

This plugin for Debian lacks this problem, but does not meet terms of service of google (Oficial example).

Or try this code:

var map = L.map( 'map' ).setView( [ 51.505, -0.09 ], 13 );

L.tileLayer( '//mt{s}.googleapis.com/vt?x={x}&y={y}&z={z}',
{
  maxZoom: 18,
  subdomains: [ 0, 1, 2, 3 ]
} ).addTo( map );

var marker = L.marker( [ 51.5, -0.09 ] ).addTo( map );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.