Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.39 KB | None | 0 0
  1. <!DOCTYPE html >
  2.   <head>
  3.     <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  4.     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  5.     <title>Using MySQL and PHP with Google Maps</title>
  6.     <style>
  7.       /* Always set the map height explicitly to define the size of the div
  8.        * element that contains the map. */
  9.       #map {
  10.         height: 100%;
  11.       }
  12.       /* Optional: Makes the sample page fill the window. */
  13.       html, body {
  14.         height: 100%;
  15.         margin: 0;
  16.         padding: 0;
  17.       }
  18.     </style>
  19.   </head>
  20.  
  21.   <body>
  22.     <div id="map"></div>
  23.  
  24.     <script>
  25.       var customLabel = {
  26.         restaurant: {
  27.           label: 'R'
  28.         },
  29.         bar: {
  30.           label: 'B'
  31.         }
  32.       };
  33.  
  34.         function initMap() {
  35.         var map = new google.maps.Map(document.getElementById('map'), {
  36.           center: new google.maps.LatLng(37.776722, -3.788846),
  37.           zoom: 12
  38.         });
  39.         var infoWindow = new google.maps.InfoWindow;
  40.  
  41.           // Change this depending on the name of your PHP or XML file
  42.           //downloadUrl('https://storage.googleapis.com/mapsdevsite/json/mapmarkers2.xml', function(data) {
  43.           downloadUrl('http://IP/phonegap/google_earth/mysql_xml.php', function(data) {
  44.             var xml = data.responseXML;
  45.             var markers = xml.documentElement.getElementsByTagName('marker');
  46.             Array.prototype.forEach.call(markers, function(markerElem) {
  47.               var name = markerElem.getAttribute('name');
  48.               var address = markerElem.getAttribute('address');
  49.               var type = markerElem.getAttribute('type');
  50.               var point = new google.maps.LatLng(
  51.                   parseFloat(markerElem.getAttribute('lat')),
  52.                   parseFloat(markerElem.getAttribute('lng')));
  53.  
  54.               var infowincontent = document.createElement('div');
  55.               var strong = document.createElement('strong');
  56.               strong.textContent = name
  57.               infowincontent.appendChild(strong);
  58.               infowincontent.appendChild(document.createElement('br'));
  59.  
  60.               var text = document.createElement('text');
  61.               text.textContent = address
  62.               infowincontent.appendChild(text);
  63.               var icon = customLabel[type] || {};
  64.               var marker = new google.maps.Marker({
  65.                 map: map,
  66.                 position: point,
  67.                 label: icon.label
  68.               });
  69.               marker.addListener('click', function() {
  70.                 infoWindow.setContent(infowincontent);
  71.                 infoWindow.open(map, marker);
  72.               });
  73.             });
  74.           });
  75.         }
  76.  
  77.  
  78.  
  79.       function downloadUrl(url, callback) {
  80.         var request = window.ActiveXObject ?
  81.             new ActiveXObject('Microsoft.XMLHTTP') :
  82.             new XMLHttpRequest;
  83.  
  84.         request.onreadystatechange = function() {
  85.           if (request.readyState == 4) {
  86.             request.onreadystatechange = doNothing;
  87.             callback(request, request.status);
  88.           }
  89.         };
  90.  
  91.         request.open('GET', url, true);
  92.         request.send(null);
  93.       }
  94.  
  95.       function doNothing() {}
  96.     </script>
  97.     <script async defer
  98.    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDOIXgooriU_0Aoer55FTlKkyo35NEK-ro&callback=initMap">
  99.     </script>
  100.   </body>
  101. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement