Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:56:46+00:00 2026-05-26T14:56:46+00:00

In my Rails app, the background consists of a fullscreen div with Google Maps

  • 0

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 () {  
  updateMap();
});

The updateMap function creates a Google Map on the div element ‘google_map’:

function updateMap()  {
      var latlng = new google.maps.LatLng(52.157927, 4.704895);
    var myOptions = {
      zoom: 10,
      center: latlng,
      disableDefaultUI: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("google_map"),
        myOptions);
    var trafficLayer = new google.maps.TrafficLayer();    
    trafficLayer.setMap(map);
    updateTrafficOnMap(map, trafficLayer);    
}

The last call is to this function:

function updateTrafficOnMap(map, overlay)
{
    overlay.setMap();
    overlay = null;
    var trafficLayer = new google.maps.TrafficLayer();    
    trafficLayer.setMap(map);

    setTimeout(function(){ updateTrafficOnMap(map, trafficLayer) }, 60000);
}

Which is supposed to update the traffic layer every minute.

Now the div is loaded correctly on page load, the layer is loaded too. However, this never updates, so there’s no real time traffic information unless you reload the whole page.

Anyone knows the magic word to make the traffic layer refresh properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:56:47+00:00Added an answer on May 26, 2026 at 2:56 pm

    So I found the answer. Apparently you cannot update the map with a new overlay while inside the timeOut function. I do not know why exactly (as for instance a ‘alert()’ does show while inside the function). I solved it using a switch statement in the updateOnTrafficMap function, so that once every minute the layout disappears, and immediately reappears using another timeOut (set to 1 ms).

    function updateMap()  {
      // the following creates a Google Map with zoom level 10 and the LatLong coordinates
      // stated below
      var latlng = new google.maps.LatLng(52.053335, 4.917755);
      var myOptions = {
        zoom: 10,
        center: latlng,
        disableDefaultUI: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("google_map"), myOptions);
      updateTrafficOnMap(map, null, 1);
    }
    
    function updateTrafficOnMap(map, trafficLayer, on)
    {
      if(on == 0) {
        trafficLayer.setMap(null);
        setTimeout(function() { updateTrafficOnMap(map, null, 1) }, 1) 
      }
      if(on == 1) {
        var trafficLayer2 = new google.maps.TrafficLayer();
        trafficLayer2.setMap(map);
        // after 300ms (or 5 minutes) update the traffic map
        setTimeout(function() { updateTrafficOnMap(map, trafficLayer2, 0)}, 300000)
      }
    }
    

    On document load you call the updateMap() function, and you should have a DIV with id “google_map” to display the map in of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

BACKGROUND : I have a Rails app where my home page is products/index. I'm
Moving rails app to production and running into the routing issues. I've read this
My rails app crashes as soon as I access a web page. My versions
Background I'm designing a Rails app to record research data. Most of it can
I have a Ruby on Rails app that needs process many background jobs simultaneously:
I have a Ruby script in my Rails app that I use to load
Well this probably isn't specific to rails, but in my rails app, I have
Background: So I have roughly (Ruby on Rails app) class A def calculate_input_datetimes #
Background I'm using the acts_as_list gem in a rails app my posts table has
I'm using delayed_job to run some background processes on my rails app. These processes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.