简体   繁体   中英

how to auto refresh div after every 1 min that contain map

i am new to stack overflow.please edit my question if it looks wrong. i have div tag with id="map" that contain google map i want to refresh that div at every 1 min.

<div id="map" style="width: 100%; height: 500px"></div>

function load() {

      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng("<?php echo $lat;?>", "<?php echo $lng;?>"),
        zoom: 13,
        mapTypeId: 'roadmap'
      });
      var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP file
      downloadUrl("mapajax.php", function(data) {
        var xml = data.responseXML;


        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("name");
          var email = markers[i].getAttribute("email");
          var phone = markers[i].getAttribute("phone");
          var status = markers[i].getAttribute("status");
          var type = markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<b>" + name + "</b> <br/>" + email+ "</b> <br/>" + phone+ "</b> <br/>" + status;
          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
    }

you can use setinterval for every sec. refresh like below , off course you can edit the function according to your need like 1 sec = 1000 ms, you can use 60000 for 1 min

setInterval(function(){ 
    load()    
}, 60000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM