Minggu, 02 Februari 2020

PHP MUlti Marker Jogja Malioboro dari Database




<?php

require_once"konmysqli.php";

date_default_timezone_set("Asia/Jakarta");

function getField($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$d= $rs->fetch_assoc();
$rs->free();
return $d;
}


$id_paket=$_GET["id"];
$sql="select * from `$tbpaket` where `id_paket`='$id_paket'";
$d=getField($conn,$sql);
$id_paket=$d["id_paket"];
$nama_paket=$d["nama_paket"];
$deskripsi=$d["deskripsi"];
$keterangan=$d["keterangan"];
$map=$d["map"];
$map2=$d["map2"];
$map3=$d["map3"];
$map4=$d["map4"];
$map5=$d["map5"];
$gambar=$d["gambar"];

if($map2==""){$map2=$map;}
if($map3==""){$map3=$map;}
if($map4==""){$map4=$map;}
if($map5==""){$map5=$map;}
$map=str_replace(" ","",$map);
$map2=str_replace(" ","",$map2);
$map3=str_replace(" ","",$map3);
$map4=str_replace(" ","",$map4);
$map5=str_replace(" ","",$map5);

$ar1=explode(",",$map);
$ar2=explode(",",$map2);
$ar3=explode(",",$map3);
$ar4=explode(",",$map4);
$ar5=explode(",",$map5);



?>
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Draggable Directions</title>
    <style>
      #right-panel {
        font-family: 'Roboto','sans-serif';
        line-height: 30px;
        padding-left: 10px;
      }

      #right-panel select, #right-panel input {
        font-size: 15px;
      }

      #right-panel select {
        width: 100%;
      }

      #right-panel i {
        font-size: 12px;
      }
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
        float: left;
        width: 63%;
        height: 100%;
      }
      #right-panel {
        float: right;
        width: 34%;
        height: 100%;
      }
      .panel {
        height: 100%;
        overflow: auto;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <div id="right-panel">
      <p>Total Distance: <span id="total"></span></p>
    </div>
    <script>
      function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 12,
          center: {lat: -6.353525, lng: 106.831629}
        });

        var directionsService = new google.maps.DirectionsService;
        var directionsRenderer = new google.maps.DirectionsRenderer({
          draggable: true,
          map: map,
          panel: document.getElementById('right-panel')
        });

        directionsRenderer.addListener('directions_changed', function() {
          computeTotalDistance(directionsRenderer.getDirections());
        });


var myLatLng1 = new google.maps.LatLng({lat: <?php echo $ar2[0];?>, lng: <?php echo $ar2[1];?>});
var myLatLng2 = new google.maps.LatLng({lat: <?php echo $ar3[0];?>, lng: <?php echo $ar3[1];?>});
var myLatLng3 = new google.maps.LatLng({lat: <?php echo $ar4[0];?>, lng: <?php echo $ar4[1];?>});



 var awal = new google.maps.LatLng({lat: <?php echo $ar1[0];?>, lng: <?php echo $ar1[1];?>});
 var ahir = new google.maps.LatLng({lat: <?php echo $ar5[0];?>, lng: <?php echo $ar5[1];?>});
// var myLatLng32 = new google.maps.LatLng({lat: -6.168428, lng: 106.827406});




  displayRoute(awal,ahir,myLatLng1, myLatLng2, myLatLng3, directionsService,directionsRenderer);
      }

      function displayRoute(origin, destination,myLatLng1, myLatLng2, myLatLng3, service, display) {
        service.route({
          origin: origin,
          destination: destination,
          waypoints: [{location: myLatLng1}, {location: myLatLng2}, {location: myLatLng3}],
          travelMode: 'DRIVING',
          avoidTolls: true
        }, function(response, status) {
          if (status === 'OK') {
            display.setDirections(response);
          } else {
            alert('Could not display directions due to: ' + status);
          }
        });
      }

      function computeTotalDistance(result) {
        var total = 0;
        var myroute = result.routes[0];
        for (var i = 0; i < myroute.legs.length; i++) {
          total += myroute.legs[i].distance.value;
        }
        total = total / 1000;
        document.getElementById('total').innerHTML = total + ' km';
      }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBhSg6I2JvHNU_jLqIpvc5MEwc_xi3Ttvg&callback=initMap">
    </script>
  </body>
</html>

<?php
//echo "$map#$map2#$map3#$map4#$map5#";
echo $ar1[0]."#".$ar1[1]."<br>";
echo $ar2[0]."#".$ar2[1]."<br>";
echo $ar3[0]."#".$ar3[1]."<br>";
echo $ar4[0]."#".$ar4[1]."<br>";
echo $ar5[0]."#".$ar5[1]."<br>";
?>

Tidak ada komentar:

Posting Komentar

global_priv WARNING Selalu

 Jika muncul pesan kesalahan: Warning in .\libraries\classes\Dbal\DbiMysqli.php#209  mysqli::query(): (HY000/1034): Index for table 'glo...