Refreshing Google Maps API V3 Layers

前端 未结 8 1758
温柔的废话
温柔的废话 2020-12-09 03:12

I\'ve been having trouble getting Google Maps API v3 to update correctly. I\'ve got a javascript timer running that should be refreshing the traffic layer periodic

8条回答
  •  北海茫月
    2020-12-09 03:51

    I haven't work with traffic layers yet, so I'm not sure if this will work for you. I read the setZoom(getZoom()) trick but when I need to refresh the tiles (the classic one. The map itself) it didn't work either. I need to show/hide a grid in Gmaps (without reloading the page)

    After searching and testing I got it working with these three lines:

            google.maps.event.trigger(map, 'resize'); // Can't remember if really helps
            map.setZoom( map.getZoom() -1 );    
            map.setZoom( map.getZoom() +1 ); // It won't flicker or make the transition between zoom levels. GMap just ignore the zoom change but redraw the tiles :/
    

    I repeat. I don't know if this works with traffic layers but test it anyways. It kept me awake 2 days.

提交回复
热议问题