Dokumen : Koneksi SQL dengan MySql

Catatan pribadi, dan untuk penggunaan pribadi
dengan sumber dari beberapa sumber, *punten lupa darimana sourcenya, digabung gabungkan soalnya. ^__^

Nama File : connect.php

<?php
$link = pg_connect
("host=localhost port=5432 dbname=postgres user=postgres password=pass");
?>

untuk file ke XML nya : sql_xml.php

<?php include "connect.php"; ?>
<?php
	function parseToXML($htmlStr)
	{
		$xmlStr=str_replace('<','&lt;',$htmlStr);
		$xmlStr=str_replace('>','&gt;',$xmlStr);
		$xmlStr=str_replace('"','&quot;',$xmlStr);
		$xmlStr=str_replace("'",''',$xmlStr);
		$xmlStr=str_replace("&",'&amp;',$xmlStr);
		return $xmlStr;
	}

// Select all the rows in the markers table
      
	$query = 'select * from banks';	
	$result = pg_exec($link, $query);
	pg_close($link);
	
	
	header("Content-type: text/xml");
	
// Start XML file, echo parent node
	echo '<markers>';

// Iterate through the rows, printing XML nodes for each
	while ($row = @pg_fetch_assoc($result)){

// ADD TO XML DOCUMENT NODE
	echo '<marker ';
	echo 'name="' . parseToXML($row['bank']) . '" ';
	echo 'lat="' . $row['lat'] . '" ';
	echo 'lng="' . $row['long'] . '" ';
	echo '/>';
}

// End XML file
	echo '</markers>';
	
?>

Generate SQLnya dengan Query langsung,

20161116-query-table

 

 

 

 

 

dan tampilan XML nya
20161116-query-php

 

 

 

 

Nama File : bank.php

<!DOCTYPE html >
	<head>
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    
	<title>PHP/MySQL & Google Maps Example</title>
    
	<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE API"
            type="text/javascript"></script>
    <script type="text/javascript">
    
//<![CDATA[

    var customIcons = 
	{
      MANDIRI: {icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/yellow.png'},
	  BNI: {icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/green.png'},
      BCA: {icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/red.png'}
    };

    function load() {
      var map = new google.maps.Map(document.getElementById("map"), 
	  {
        center: new google.maps.LatLng(-5.235577266, 119.4905506867),
        zoom: 14,
		mapTypeId: 'roadmap'
      });
      var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP file
      downloadUrl("sql_xml.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 latitude = markers[i].getAttribute("lat");
		  var longitude = markers[i].getAttribute("lng");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<b>" + name +"</b> <br/>" + latitude +" | "+ longitude + "</b> <br/>";
          var icon = customIcons[name] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
    }

    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}

    //]]>

  </script>

  </head>

  <body onload="load()">
    <div id="map" style="width: 1800px; height: 800px"></div>
  </body>

</html>

20161116-map-gmap

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s