Guest User

Untitled

a guest
Feb 27th, 2018
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "mbcdb";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. // Check connection
  10. if ($conn->connect_error) {
  11. die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14. $sql = mysql_query("SELECT * FROM markers");
  15. $row = mysql_fetch_array($sql);
  16. $lat = $row['lat'];
  17. $lng = $row['lng'];
  18. // mimic a result array from MySQL
  19. $result = array(array('lat'=>$lat,'lng'=>$lng));
  20. ?>
  21. <script async defer
  22. src="https://maps.googleapis.com/maps/api/js?
  23. key=AIzaSyBZ2nfVhxwcAagjUeQ50NiDiN2dQDHTypA&callback=initialize">
  24. </script>
  25. <script type="text/javascript">
  26. var map;
  27. function initialize() {
  28. // Set static latitude, longitude value
  29. var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?
  30. >);
  31. // Set map options
  32. var myOptions = {
  33. zoom: 16,
  34. center: latlng,
  35. panControl: true,
  36. zoomControl: true,
  37. scaleControl: true,
  38. mapTypeId: google.maps.MapTypeId.ROADMAP
  39. }
  40. // Create map object with options
  41. map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  42. <?php
  43. // uncomment the 2 lines below to get real data from the db
  44. $result = mysql_query("SELECT * FROM markers");
  45. while ($row = mysql_fetch_array($result))
  46. echo "addMarker(new google.maps.LatLng(".$row['lat'].", ".$row['long']."),
  47. map);";
  48. ?>
  49. }
  50.  
  51. function addMarker(latLng, map) {
  52. var marker = new google.maps.Marker({
  53. position: latLng,
  54. map: map,
  55. draggable: true, // enables drag & drop
  56. animation: google.maps.Animation.DROP
  57. });
  58.  
  59. var contentString = latLng.lat() + " , " + latLng.lng();
  60.  
  61. geocoder.geocode({'latLng': latlng}, function(results, status) {
  62. if (status == google.maps.GeocoderStatus.OK) {
  63. if (results[1]) {
  64. map.setZoom(11);
  65. marker = new google.maps.Marker({
  66. position: latlng,
  67. map: map
  68. });
  69. infowindow.setContent(results[1].formatted_address);
  70. infowindow.open(map, marker);
  71. } else {
  72. alert('No results found');
  73. }
  74. } else {
  75. alert('Geocoder failed due to: ' + status);
  76. }
  77. });
  78.  
  79. google.maps.event.addListener(marker, 'click', function() {
  80. infowindow.open(map,marker);
  81. });
  82. }
  83. </script>
  84.  
  85. <div class="container text-center">
  86. <div class="row content">
  87. <div class="col-md-12">
  88. <h1>Welcome to Mission BridCon</h1><br>
  89. <div id="map_canvas" style="width:100%;height:500px"></div>
  90. </div>
  91. </div>
  92. </div>
Add Comment
Please, Sign In to add comment