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
try this code snippet, may be this help you out
function init() {
var map,
trafficLayer,
mapTimerHandle;
var mapDiv = document.getElementById('map');
map = new google.maps.Map(mapDiv, {
zoom: 14,
center: new google.maps.LatLng(40.7127, -74.0059)
});
trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}
$(document).ready(function () {
init();
setInterval(function () {
google.maps.event.trigger(map, 'resize');
map.fitBounds();
}, 2000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
<div id="map" style="width:600px; height:450px"></div>
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.