Advertisement
cdsatrian

gmap tourism

Jul 27th, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.29 KB | None | 0 0
  1. <?php
  2. /********************************
  3. FILENAME : gmap.tourism.php
  4. PURPOSE  : plot various marker on map
  5. CREATE BY: CAHYA DSN
  6. CREATE ON: 2014-07-27
  7. *********************************
  8.  
  9. CREATE DATABASE IF NOT EXISTS `gmap`;
  10. USE gmap;
  11.  
  12. DROP TABLE IF EXISTS `kategori`;
  13. CREATE TABLE `kategori` (
  14.   `id` tinyint UNSIGNED NOT NULL AUTO_INCREMENT,
  15.   `nama` varchar(255) DEFAULT NULL,
  16.   PRIMARY KEY (`id`)
  17. ) ENGINE=MyISAM;
  18.  
  19. INSERT INTO `kategori`(`nama`)
  20. VALUES ('wisata'),('restoran');
  21.  
  22. DROP TABLE IF EXISTS `lokasi`;
  23. CREATE TABLE `lokasi` (
  24.   `id` int(11) NOT NULL AUTO_INCREMENT,
  25.   `kategori_id` tinyint UNSIGNED NOT NULL,
  26.   `nama` varchar(255) DEFAULT NULL,
  27.   `lat` FLOAT,
  28.   `lng` FLOAT,
  29.   PRIMARY KEY (`id`)
  30. ) ENGINE=MyISAM;
  31.  
  32. INSERT INTO `lokasi`(`kategori_id`,`nama`,`lat`,`lng`)
  33. VALUES
  34. (1,'wisata1',40.756054,-73.986951),
  35. (2,'restoran1',47.620973,-102.347276),
  36. (1,'wisata2',37.775206,-122.419209);
  37. */
  38. ?>
  39. <!doctype html>
  40. <html>
  41.   <head>
  42.     <title>GMap Tourism</title>
  43.     <script type="text/javascript"   src="http://maps.google.com/maps/api/js?sensor=false"></script>
  44.     <script type='text/javascript' language='javascript'>
  45. (function() {
  46. // Creating an array that will contain all of our 'lokasi' icons
  47.    var lokasiIcons = [];
  48.    lokasiIcons['restoran'] = new google.maps.MarkerImage(
  49.      'http://mapicons.nicolasmollet.com/wp-content/uploads/mapicons/shape-default/color-8c4eb8/shapecolor-color/shadow-1/border-dark/symbolstyle-white/symbolshadowstyle-dark/gradient-no/restaurant.png',
  50.      new google.maps.Size(48, 48),
  51.      null,
  52.      new google.maps.Point(24, 24)
  53.    );
  54.    lokasiIcons['wisata'] = new google.maps.MarkerImage(
  55.      'http://mapicons.nicolasmollet.com/wp-content/uploads/mapicons/shape-default/color-8c4eb8/shapecolor-color/shadow-1/border-dark/symbolstyle-white/symbolshadowstyle-dark/gradient-no/hostel_0star.png',
  56.      new google.maps.Size(48, 48),
  57.      null,
  58.      new google.maps.Point(24, 24)
  59.    );
  60.    window.onload = function() {
  61.    // Creating a map
  62.      var options = {
  63.        zoom: 3,
  64.        center: new google.maps.LatLng(37.09, -95.71),
  65.        mapTypeId: google.maps.MapTypeId.ROADMAP
  66.      };
  67.      var map = new google.maps.Map(document.getElementById('map'), options);
  68.      // Creating a JSON object with weather data
  69. <?php
  70. // database configuration
  71. $dbhost='localhost';
  72. $dbuser='root';
  73. $dbpass='';
  74. $dbname='gmap';
  75. // database connection
  76. $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
  77. $sql="
  78. SELECT a.nama, a.lat, a.lng, b.nama AS kategori
  79. FROM lokasi a
  80. JOIN kategori b ON b.id=a.kategori_id";
  81. $result=$db->query($sql);
  82. $data=array();
  83. while($record=$result->fetch_assoc()){
  84.   $data[]=$record;
  85. }
  86. echo '   var dataLokasi = '.json_encode(array('lokasi'=>$data));
  87. ?>
  88.      // Looping through the 'lokasi' array in 'dataLokasi'
  89.      for (var i = 0; i < dataLokasi.lokasi.length; i++) {
  90.        // creating a variable that will hold the current 'lokasi' object
  91.        var lokasi = dataLokasi.lokasi[i];
  92.        // Creating marker
  93.        var marker = new google.maps.Marker({
  94.          position: new google.maps.LatLng(lokasi.lat, lokasi.lng),
  95.          map: map,
  96.          icon: lokasiIcons[lokasi.kategori]
  97.        });
  98.      }
  99.    }
  100. })();
  101. </script>
  102. <body>
  103.   <div id='map' style="width:600px;height:400px;display:block"></div>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement