Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.48 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  6. <meta charset="utf-8">
  7. <link rel="stylesheet" type="text/css" href="css/util.css">
  8. <link rel="stylesheet" type="text/css" href="css/main.css">
  9. <link rel="stylesheet" type="text/css" href="vendor/jquery/jquery-3.2.1.min.js">
  10. <link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
  11. <script src="vendor/jquery/jquery-3.2.1.min.js"></script>
  12. <title>Reverse Geocoding</title>
  13. <style>
  14. @import url(https://fonts.googleapis.com/css?family=Roboto:400,300);
  15.  
  16. /* Always set the map height explicitly to define the size of the div
  17. * element that contains the map. */
  18. #map {
  19. height: 100%;
  20. }
  21.  
  22. #map .centerMarker {
  23. position: absolute;
  24. /*url of the marker*/
  25. background: url(http://maps.gstatic.com/mapfiles/markers2/marker.png) no-repeat;
  26. /*center the marker*/
  27. top: 50%;
  28. left: 50%;
  29. z-index: 1;
  30. /*fix offset when needed*/
  31. margin-left: -10px;
  32. margin-top: -34px;
  33. /*size of the image*/
  34. height: 34px;
  35. width: 20px;
  36. cursor: pointer;
  37. }
  38.  
  39.  
  40. /* Optional: Makes the sample page fill the window. */
  41. html,
  42. body {
  43. height: 100%;
  44. margin: 0;
  45. padding: 0;
  46. }
  47.  
  48. #floating-panel {
  49. position: absolute;
  50. top: 10px;
  51. left: 25%;
  52. z-index: 5;
  53. background-color: #fff;
  54. padding: 5px;
  55. border: 1px solid #999;
  56. text-align: center;
  57. font-family: 'Roboto', 'sans-serif';
  58. line-height: 30px;
  59. padding-left: 10px;
  60. }
  61.  
  62. #floating-panel {
  63. position: absolute;
  64. top: 5px;
  65. left: 50%;
  66. margin-left: -180px;
  67. width: 350px;
  68. z-index: 5;
  69. background-color: #fff;
  70. padding: 5px;
  71. border: 1px solid #999;
  72. }
  73.  
  74. #latlng {
  75. width: 225px;
  76. }
  77.  
  78. .loading-bro {
  79. margin: 50px auto;
  80. width: 150px;
  81. }
  82.  
  83. .finish {
  84. margin: 50px auto;
  85. width: 150px;
  86. }
  87.  
  88. .loading-bro>h1 {
  89. text-align: center;
  90. font-size: 2.5em;
  91. margin-bottom: 1em;
  92. font-weight: 300;
  93. color: #8E8E8E;
  94. }
  95.  
  96. #load {
  97. width: 150px;
  98. animation: loading 3s linear infinite;
  99. }
  100.  
  101. #load #loading-inner {
  102. stroke-dashoffset: 0;
  103. stroke-dasharray: 300;
  104. stroke-width: 10;
  105. stroke-miterlimit: 10;
  106. stroke-linecap: round;
  107. animation: loading-circle 2s linear infinite;
  108. stroke: #51BBA7;
  109. fill: transparent;
  110. }
  111.  
  112. @keyframes loading {
  113. 0% {
  114. transform: rotate(0);
  115. }
  116.  
  117. 100% {
  118. transform: rotate(360deg);
  119. }
  120. }
  121.  
  122. @keyframes loading-circle {
  123. 0% {
  124. stroke-dashoffset: 0;
  125. }
  126.  
  127. 100% {
  128. stroke-dashoffset: -600;
  129. }
  130. }
  131. </style>
  132. </head>
  133.  
  134. <body>
  135. <!-- <div class="loading-bro">
  136. <h1>Loading</h1>
  137. <svg id="load" x="0px" y="0px" viewBox="0 0 150 150">
  138. <circle id="loading-inner" cx="75" cy="75" r="60" />
  139. </svg>
  140. </div>
  141. <div class="finish" style="display: none;">
  142. <h1>Success</h1>
  143. </div> -->
  144. <input type="text" id="latitude" placeholder="Latitude" />
  145. <input type="text" id="longitude" placeholder="Longitude" />
  146. <div id="map"></div>
  147. <script>
  148. function initMap() {
  149. var map = new google.maps.Map(document.getElementById('map'), {
  150. center: { lat: -34.397, lng: 150.644 },
  151. zoom: 17
  152. });
  153. var geocoder = new google.maps.Geocoder;
  154. var infowindow = new google.maps.InfoWindow;
  155.  
  156. if (navigator.geolocation) {
  157. navigator.geolocation.getCurrentPosition(function (position) {
  158. var pos = {
  159. lat: position.coords.latitude,
  160. lng: position.coords.longitude
  161.  
  162. };
  163. document.getElementById('latitude').value = position.coords.latitude;
  164. document.getElementById('longitude').value = position.coords.longitude;
  165.  
  166. google.maps.event.addListener(map, 'center_changed', function () {
  167. document.getElementById('latitude').value = map.getCenter().lat();
  168. document.getElementById('longitude').value = map.getCenter().lng();
  169.  
  170. });
  171.  
  172. var latlng = { lat: parseFloat(escape(document.getElementById('latitude').value)), lng: parseFloat(escape(document.getElementById('longitude').value)) };
  173. geocoder.geocode({ 'location': latlng }, function (results, status) {
  174. if (status === 'OK') {
  175. // $('.loading-bro').hide();
  176. // $('.finish').show();
  177. if (results[0]) {
  178. var marker = new google.maps.Marker({
  179. position: latlng,
  180. map: map,
  181. visible: false
  182. });
  183. var url = 'http://127.0.0.1/reverse_geolocation/map_db_post.php?&lat=' + position.coords.latitude + '&lng=' + position.coords.longitude + '&address=' + results[0].formatted_address;
  184. downloadUrl(url, function (data, responseCode) {
  185. if (responseCode == 200 && data.length <= 1) {
  186. infowindow.close();
  187. messagewindow.open(map, marker);
  188. }
  189. });
  190. console.log(results[0].formatted_address);
  191. // infowindow.setContent(results[0].formatted_address);
  192. // infowindow.open(map, marker);
  193. map.setCenter(pos);
  194. google.maps.event.addListener(map, 'center_changed', function () {
  195. geocodePosition(marker.getPosition());
  196. $('<div/>').addClass('centerMarker').appendTo(map.getDiv())
  197. //do something onclick
  198. .ready(function () {
  199. var that = $(this);
  200. if (!that.data('win')) {
  201. that.data('win', new google.maps.InfoWindow({
  202. content: results[0].formatted_address
  203. }));
  204. that.data('win').bindTo('position', map, 'center');
  205. }
  206. that.data('win').open(map);
  207. });
  208. });
  209.  
  210. } else {
  211. window.alert('No results found');
  212. }
  213. } else {
  214. window.alert('Geocoder failed due to: ' + status);
  215. }
  216. });
  217.  
  218.  
  219. }, function () {
  220. handleLocationError(true, infoWindow, map.getCenter());
  221. });
  222. } else {
  223. // Browser doesn't support Geolocation
  224. handleLocationError(false, infoWindow, map.getCenter());
  225. }
  226.  
  227. function downloadUrl(url, callback) {
  228. var request = window.ActiveXObject ?
  229. new ActiveXObject('Microsoft.XMLHTTP') :
  230. new XMLHttpRequest;
  231.  
  232.  
  233. request.onreadystatechange = function () {
  234. if (request.readyState == 4) {
  235. request.onreadystatechange = doNothing;
  236. callback(request.responseText, request.status);
  237. }
  238. };
  239.  
  240. request.open('GET', url, true);
  241. request.send(null);
  242. }
  243.  
  244. function doNothing() {
  245. }
  246.  
  247.  
  248. }
  249. google.maps.event.addDomListener(window, 'load', initMap);
  250. // function initialize() {
  251. // var mapOptions = {
  252. // zoom: 14,
  253. // center: new google.maps.LatLng(52.5498783, 13.425209099999961),
  254. // mapTypeId: google.maps.MapTypeId.ROADMAP
  255. // };
  256. // map = new google.maps.Map(document.getElementById('map_canvas'),
  257. // mapOptions);
  258. // google.maps.event.addListener(map, 'center_changed', function () {
  259. // document.getElementById('default_latitude').value = map.getCenter().lat();
  260. // document.getElementById('default_longitude').value = map.getCenter().lng();
  261. // });
  262. // $('<div/>').addClass('centerMarker').appendTo(map.getDiv())
  263. // //do something onclick
  264. // .click(function () {
  265. // var that = $(this);
  266. // if (!that.data('win')) {
  267. // that.data('win', new google.maps.InfoWindow({
  268. // content: 'this is the center'
  269. // }));
  270. // that.data('win').bindTo('position', map, 'center');
  271. // }
  272. // that.data('win').open(map);
  273. // });
  274. // }
  275.  
  276. // google.maps.event.addDomListener(window, 'load', initialize);
  277.  
  278.  
  279. </script>
  280. <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBQPUqVEEU8Mlk56iWMA0j39foTqDdZA7k&callback=initMap">
  281. </script>
  282. </body>
  283.  
  284. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement