Google Maps refresh traffic layer

前端 未结 3 784
误落风尘
误落风尘 2020-12-17 06:03

In my Rails app, the background consists of a fullscreen div with Google Maps and a traffic layer. This is what gets called on page load:

$(function () {  
         


        
3条回答
  •  我在风中等你
    2020-12-17 06:16

    A setInterval over the whole initialize routine got me the refreshing that I desired. options.ts_google_map_traffic_refresh_milliseconds is set to the milliseconds you desire.

     setInterval(_ts_map_initialize, options.ts_google_map_traffic_refresh_milliseconds);
    
        function _ts_map_initialize(){              
            console.log('function _ts_map_initialize()')
            var myLatlng = new google.maps.LatLng(options.ts_google_map_traffic_latHome,options.ts_google_map_traffic_lonHome);
            var myOptions = {
              zoom: ts_int_zoomLevel,
              center: myLatlng,
              panControl: false,              
              zoomControl: false,
              streetViewControl: false,
              overviewMapControl: false,              
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              styles:[{
                  featureType:"poi",
                  elementType:"labels",
                  stylers:[{
                      visibility:"off"
                  }]
              }]              
            }
            map = new google.maps.Map(document.getElementById('ts_google_map_traffic_canvas'), myOptions);
            defaultBounds = map.getBounds();
    
            trafficLayer = new  google.maps.TrafficLayer(); //add the layer - don't view it unless user toggles button  
    
            trafficLayer.setMap(map);
    

    }

    enter code here
    

提交回复
热议问题