Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 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: 50%;
  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. <html>
  22. <body>
  23. <div id="map"></div>
  24.  
  25. <script>
  26. var customLabel = {
  27. restaurant: {
  28. label: 'R'
  29. },
  30. bar: {
  31. label: 'B'
  32. }
  33. };
  34.  
  35. function initMap() {
  36. var map = new google.maps.Map(document.getElementById('map'), {
  37. center: new google.maps.LatLng(-7.2764265, 112.7959489),
  38. zoom: 12
  39. });
  40. var infoWindow = new google.maps.InfoWindow;
  41.  
  42. // Change this depending on the name of your PHP or XML file
  43. downloadUrl('http://localhost/lomba/findData.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 id = markerElem.getAttribute('id');
  48. var name = markerElem.getAttribute('name');
  49. var bpm = markerElem.getAttribute('bpm');
  50. var type = markerElem.getAttribute('type');
  51. var point = new google.maps.LatLng(
  52. parseFloat(markerElem.getAttribute('lat')),
  53. parseFloat(markerElem.getAttribute('lng')));
  54.  
  55. var infowincontent = document.createElement('div');
  56. var strong = document.createElement('strong');
  57. strong.textContent = name
  58. infowincontent.appendChild(strong);
  59. infowincontent.appendChild(document.createElement('br'));
  60.  
  61. var text = document.createElement('text');
  62. text.textContent = bpm
  63. infowincontent.appendChild(text);
  64. var icon = customLabel[type] || {};
  65. var marker = new google.maps.Marker({
  66. map: map,
  67. position: point,
  68. label: icon.label
  69. });
  70. marker.addListener('click', function() {
  71. infoWindow.setContent(infowincontent);
  72. infoWindow.open(map, marker);
  73. });
  74. });
  75. });
  76. }
  77.  
  78.  
  79.  
  80. function downloadUrl(url, callback) {
  81. var request = window.ActiveXObject ?
  82. new ActiveXObject('Microsoft.XMLHTTP') :
  83. new XMLHttpRequest;
  84.  
  85. request.onreadystatechange = function() {
  86. if (request.readyState == 4) {
  87. request.onreadystatechange = doNothing;
  88. callback(request, request.status);
  89. }
  90. };
  91.  
  92. request.open('GET', url, true);
  93. request.send(null);
  94. }
  95.  
  96. function doNothing() {}
  97. </script>
  98. <script async defer
  99. src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDYAxNaq5rpCf6aSUkvbc5WjIIQ0BK4sIQ&callback=initMap">
  100. </script>
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement