Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. <?php require_once('connection.php'); ?>
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <!-- Required meta tags -->
  6. <meta charset="utf-8">
  7. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  8.  
  9. <!-- Bootstrap CSS -->
  10. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
  11.  
  12. <title>Google maps</title>
  13. <style>
  14. #map {
  15. height: 400px;
  16. width: 100%;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <h1>Google maps</h1>
  22.  
  23. <div id="map"></div>
  24.  
  25. <div class="container-fluid">
  26. <div class="row">
  27. <div class="col-sm-4">
  28. <h1>Manuaalne lisamine</h1>
  29. <input type="hidden" id="point_change_id" value="0">
  30. <div class="form-group">
  31. <label for="pointAddName">Name</label>
  32. <input type="text" class="form-control" id="pointAddName" placeholder="Name">
  33. </div>
  34. <div class="form-group">
  35. <label for="pointAddLatitude">Latitude</label>
  36. <input type="text" class="form-control" id="pointAddLatitude" placeholder="Latitude">
  37. </div>
  38. <div class="form-group">
  39. <label for="pointAddLongitude">Longitude</label>
  40. <input type="text" class="form-control" id="pointAddLongitude" placeholder="Longitude">
  41. </div>
  42. <button type="button" class="btn btn-primary" id="pointAddBtn">Submit</button>
  43. <div class="jquery-message"></div>
  44. <hr>
  45. </div>
  46. <div class="col-md-8">
  47. <table class="table table-hover table-bordered">
  48. <thead>
  49. <tr>
  50. <th>Name</th>
  51. <th>Lat, lng</th>
  52. <th></th>
  53. </tr>
  54. </thead>
  55. <tbody id="markers_table"></tbody>
  56. </table>
  57. </div>
  58. </div>
  59. </div>
  60.  
  61. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  62. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
  63. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
  64.  
  65. <script>
  66. function initMap() {
  67. var uluru = {lat: -25.363, lng: 131.044};
  68. var map = new google.maps.Map(document.getElementById('map'), {
  69. zoom: 4,
  70. center: uluru
  71. });
  72.  
  73. $.getJSON("get_markers.php", function(data) {
  74. if(data.status == 1){
  75. for(i = 0; i < data.markers.length; i++){
  76. const curMarker = data.markers[i];
  77. var marker = new google.maps.Marker({
  78. position: {lat: parseFloat(curMarker.latitude),
  79. lng: parseFloat(curMarker.longitude)},
  80. map: map
  81. });
  82.  
  83. $("#markers_table").append('<tr>' +
  84. '<td>' + curMarker.name + '</td>' +
  85. '<td>' + parseFloat(curMarker.latitude) + ', ' + parseFloat(curMarker.longitude) + '</td>' +
  86. '<td>' +
  87. '<button type="button" class="btn btn-info" id="editBtn" data-point-id="'+ curMarker.ID +'">Edit</button>' +
  88. '<button type="button" class="btn btn-danger" id="deleteBtn" data-point-id="'+ curMarker.ID +'">Delete</button>' +
  89. '</td>' +
  90. '</tr>');
  91. }
  92. }else{
  93. $(".jquery-message").html('<div class="alert alert-warning">' + data.message + '</div>');
  94. }
  95. });
  96.  
  97. /*marker.addListener('click', function(){
  98. map.setCenter(marker.getPosition());
  99. });*/
  100.  
  101. google.maps.event.addListener(map, 'click', function(event) {
  102. $("#pointAddLatitude").val(event.latLng.lat);
  103. $("#pointAddLongitude").val(event.latLng.lng);
  104. });
  105. }
  106.  
  107. $("#pointAddBtn").on("click", function(){
  108. const name = $("#pointAddName").val(),
  109. lat = $("#pointAddLatitude").val(),
  110. lng = $("#pointAddLongitude").val();
  111.  
  112. $.post('jquery/insert-new-point.php', {name: name, lat: lat, lng: lng})
  113. .done(function(data){
  114. const json = JSON.parse(data);
  115. let alertClass = 'info';
  116. if(json.status == 0){
  117. alertClass = 'warning';
  118. }
  119.  
  120. $(".jquery-message").html('<div class="alert alert-' + alertClass + '">' + json.message + '</div>');
  121. });
  122. });
  123. </script>
  124. <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA_BIjwknbV0ROM9uprm3dO4v3Lkju9JCw&callback=initMap">
  125. </body>
  126. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement