1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to refresh leaflet markers after some interval

Discussion in 'JavaScript' started by Jallah, Jan 9, 2017.

  1. #1
    I have made leaflet map with following code which uses longitude and latitude from mysql database as given below
    <script>
    
        var planes = [
    
    <?php
    
    
              $DB = mysqli_connect('localhost','username','password','abc');
              $Q = "SELECT location, length, width FROM abcstat WHERE siteid='xyz'";
              $R = mysqli_query($DB,$Q);
              //start loop
              //while or foreach
    $results=[];                                                     // define array
    while($row = mysqli_fetch_assoc($R)){
        $results[] = "['{$row['location']}',{$row['length']},{$row['width']}]";  // add to array
    }
    $final = join(",\r\n", $results);
    
    echo $final;
    
              ?>
           
            ];
    
            var map = L.map('map').setView([19.426216, 15.7166481], 1);
            mapLink =
                '<a href="http://openstreetmap.org">OpenStreetMap</a>';
            L.tileLayer(
                'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                attribution: '&copy; ' + mapLink + ' Contributors',
                maxZoom: 8,
                }).addTo(map);
    
            for (var i = 0; i < planes.length; i++) {
                marker = new L.marker([planes[i][1],planes[i][2]])
                    .bindPopup(planes[i][0])
                    .addTo(map);
            }
                  
        </script>
    
    Code (markup):
    This load a map in div with marker loaded by above mysql query. div is given below
    <div id="map" style="width: 650px; height: 400px"></div>
    
    Code (markup):
    and this works perfectly and shows marker points when page is loaded. But i want to refresh marker points after some time say 10 sec etc.without reloading web page. How to do this. Thanks in advance
     
    Jallah, Jan 9, 2017 IP
  2. fehtrar

    fehtrar Active Member

    Messages:
    11
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    80
    #2
    Use setInterval()

    use ajax to get data from server then
     
    fehtrar, Jan 18, 2017 IP
  3. Jallah

    Jallah Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    How to do that?
     
    Jallah, Jan 20, 2017 IP