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

  • Home
  • SEARCH
  • 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 8771365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:46:04+00:00 2026-06-13T17:46:04+00:00

Good morning. I have the next code which put some markers in a map

  • 0

Good morning.

I have the next code which put some markers in a map from a xml file, every 5 seconds I call again the xml file and I update the position of the markers, but the problem is that the infowindows are not updated. Does anyone knows how to update them=

Here you have the code:

//<![CDATA[

var side_bar_html = ""; 


var gmarkers = []; 

var map = null;
var markerclusterer = null;




function myclick(i) {
    google.maps.event.trigger(gmarkers[i], "click");
    map.setZoom(map.getZoom()+2); 
}

function initialize() {
    // create the map
    var myOptions = {
        zoom: 12,
        center: new google.maps.LatLng(37.169619,-3.756981),
        mapTypeControl: true,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
            },
        navigationControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
}
function getMarkers() {
    google.maps.event.addListener(map, 'click', function() {
        infowindow.close();
    });


    downloadUrl("vehiculos.asp", function(doc) {
        var xmlDoc = xmlParse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new google.maps.LatLng(lat,lng);
            var imei = markers[i].getAttribute("imei");
            var alias = markers[i].getAttribute("alias");
            var speed= markers[i].getAttribute("speed");
            var timestamp= markers[i].getAttribute("timestamp");
            var estado= markers[i].getAttribute("estado");
            var conectado= markers[i].getAttribute("conectado");
            var altitude= markers[i].getAttribute("altitude");
            var angle= markers[i].getAttribute("angle");
            var html="<b>"+alias+" "+speed+" km/h <br/> "+timestamp;


            var marker = createMarker(point,alias+" "+imei,html,estado,alias, speed, timestamp, altitude, angle);
        }   
        markerCluster = new MarkerClusterer(map, gmarkers);

    });
}
var infowindow = new google.maps.InfoWindow(
{ 

    size: new google.maps.Size(150,60)
});

setInterval(function updateMarkers() {
    google.maps.event.addListener(map, 'click', function() {
        infowindow.close();
    });

    downloadUrl("vehiculos.asp", function(doc) {
        var xmlDoc = xmlParse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new google.maps.LatLng(lat,lng);
            var imei = markers[i].getAttribute("imei");
            var alias = markers[i].getAttribute("alias");
            var speed= markers[i].getAttribute("speed");
            var timestamp= markers[i].getAttribute("timestamp");
            var estado= markers[i].getAttribute("estado");
            var conectado= markers[i].getAttribute("conectado");
            var altitude= markers[i].getAttribute("altitude");
            var angle= markers[i].getAttribute("angle");

            var html="<b>"+alias+" a "+speed+" km/h <br/> "+timestamp;


            var newLatLng = gmarkers[i].setPosition(point,alias+" "+imei,html,estado,alias,speed,timestamp,altitude,angle);


        }   
        markerCluster = new MarkerClusterer(map, gmarkers); 
    });

}, 5000);
//finish updateMarkers

function createMarker(latlng, imei, html, estado, alias, speed, timestamp, altitude, angle) {
    if(estado == 1)
        image = '/artworks/icons/truck_green3.png';
    else
        image = '/artworks/icons/truck_red.png';

    var textoLabel= alias+" speed: "+ speed+" km/h";
    var contentString = html;
    var newLatLng = new MarkerWithLabel({
        position: latlng,
        icon: image,
        // map: map,
        draggable: true,

        flat: true,
        labelContent: textoLabel,
        labelAnchor: new google.maps.Point(40, 0),
        labelClass: "labels", // the CSS class for the label
        labelStyle: {
            opacity: 0.50
        },
        zIndex: Math.round(latlng.lat()*-100000)<<5
    });

    google.maps.event.addListener(newLatLng, 'click', function() {
        infowindow.setContent(timestamp + alias); 
        infowindow.open(map,newLatLng);
    });

    gmarkers.push(newLatLng);

// side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + imei +'<\/a><br>';
}
  • 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-06-13T17:46:05+00:00Added an answer on June 13, 2026 at 5:46 pm

    You are not assigning the event handler in the setInterval function, so no infowindows.

    Add this code to the setInterval() after creating the marker

            google.maps.event.addListener(newLatLng, 'click', function() {
            infowindow.setContent(timestamp + alias); 
            infowindow.open(map,newLatLng);
    

    This may result in a closure problem as you are in a loop. So you can do something like the solutions in this Passing values in for loop to event listeners- Javascript.

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

Sidebar

Related Questions

Good morning. I have an XML file which contains lists of warning and errors
Good Morning All! I have been developing a project for some time in which
Good Morning, I have copied this code from somewere <script type=text/javascript> $(function() { setInterval(rotateImages(),
good morning programers, I have this small code which content a news control panel
Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
Good morning. I've been having this issue for some days and have been lokking
Good morning, I have to use the properties from DeviceNetworkInformation in my application. (http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation.devicenetworkinformation(v=vs.92).aspx)
Good Morning All, I have code similar to the following try{ using(var tx =
Good Morning All, I have a project which will be distributed as an Excel
Good Morning/Afternoon all, I have a ASP:grid which displays current versions of Terms and

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.