Skip to content
Advertisement

leaflet marker doenst show

After I make a change at configuration of the sql, the map does not show, I tried to echo the php code at the bottom, but it still fine

enter image description here

I look to my other project but it still work fine.

<script>
      // initialize Leaflet
      var map = L.map('map').setView([-7.454655, 111.019499], 13);
      var greenIcon = new L.Icon({
  iconUrl: 'images/1.png'
});
      var yellowIcon = new L.Icon({
  iconUrl: 'images/2.png'
});
      var redIcon = new L.Icon({
  iconUrl: 'images/3.png'
});
      // add the OpenStreetMap tiles
      L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        maxZoom: 19,
        attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
      }).addTo(map);
      // show the scale bar on the lower left corner
      L.control.scale().addTo(map);

      function addShape(name, cluster,lat ,lng) {
      var clusterJson = cluster;
        var latitude = lat;
        var longitude = lng;
      if(clusterJson==1) {
        keterangan = 'mikro';
      L.marker([latitude,longitude,12], {icon: redIcon}) .bindPopup("<strong>" + name + "</strong><br/>Termasuk Cluster : " + keterangan).addTo(map);
  }
      if(clusterJson==2) {
        keterangan = 'kecil';
      L.marker([latitude,longitude,12], {icon: yellowIcon}) .bindPopup("<strong>" + name + "</strong><br/>Termasuk Cluster : " + keterangan).addTo(map);
  }
      if(clusterJson==3) {
        keterangan = 'menengah';
      L.marker([latitude,longitude,12], {icon: greenIcon}) .bindPopup("<strong>" + name + "</strong><br/>Termasuk Cluster : " + keterangan).addTo(map);
  }
      }
<?php 
          $query = mysqli_query($connect,"SELECT * from data");
          while ($data = mysqli_fetch_array($query)) {
            $nama = $data['nama'];
            $cluster= $data['cluster'];
            $lat= $data['lat'];
            $lng= $data['lng'];
            echo ("addShape(".$nama.",".$cluster.",".$lat.",".$lng.");n"); 
          }
          ?>
    </script>

Advertisement

Answer

in the end i try to remake the database, and it work!!, idk why the error happen, the data i input to database is same as before. picture

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement