Refreshing Google Maps API V3 Layers

前端 未结 8 1762
温柔的废话
温柔的废话 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:25

    The way you are refreshing the layer is working fine.

    Here is your code edited to prove this:

    
    
        Map Testing
        
        
    
        
    
    
        

    I added a visibility property to toggle the layer every 2 seconds. You will notice how it turns on and off. Because the way you called it I think it did not have enough time to refresh.

    Also I added the interval in the initMap function after the layer's map was first set.

    Hope that helps.

    EDIT. Just to add to this, where the traffic is real time where supported, in some cases its based on historic data and will not refresh over a short period. But the traffic data is fetched at the time of each request as specified in the docs: https://developers.google.com/maps/documentation/javascript/trafficlayer#traffic_layer

提交回复
热议问题