Guest User

Untitled

a guest
Jan 24th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  5. <meta charset="utf-8">
  6. <title>Places Search Box</title>
  7. <style>
  8. /* Always set the map height explicitly to define the size of the div
  9. * element that contains the map. */
  10. #map {
  11. height: 100%;
  12. }
  13.  
  14.  
  15. /* Optional: Makes the sample page fill the window. */
  16.  
  17. html,
  18. body {
  19. height: 100%;
  20. margin: 0;
  21. padding: 0;
  22. }
  23.  
  24. #description {
  25. font-family: Roboto;
  26. font-size: 15px;
  27. font-weight: 300;
  28. }
  29.  
  30. #infowindow-content .title {
  31. font-weight: bold;
  32. }
  33.  
  34. #infowindow-content {
  35. display: none;
  36. }
  37.  
  38. #map #infowindow-content {
  39. display: inline;
  40. }
  41.  
  42. .pac-card {
  43. margin: 10px 10px 0 0;
  44. border-radius: 2px 0 0 2px;
  45. box-sizing: border-box;
  46. -moz-box-sizing: border-box;
  47. outline: none;
  48. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  49. background-color: #fff;
  50. font-family: Roboto;
  51. }
  52.  
  53. #pac-container {
  54. padding-bottom: 12px;
  55. margin-right: 12px;
  56. }
  57.  
  58. .pac-controls {
  59. display: inline-block;
  60. padding: 5px 11px;
  61. }
  62.  
  63. .pac-controls label {
  64. font-family: Roboto;
  65. font-size: 13px;
  66. font-weight: 300;
  67. }
  68.  
  69. #pac-input {
  70. background-color: #fff;
  71. font-family: Roboto;
  72. font-size: 15px;
  73. font-weight: 300;
  74. margin-left: 12px;
  75. padding: 0 11px 0 13px;
  76. text-overflow: ellipsis;
  77. width: 400px;
  78. }
  79.  
  80. #pac-input:focus {
  81. border-color: #4d90fe;
  82. }
  83.  
  84. #title {
  85. color: #fff;
  86. background-color: #4d90fe;
  87. font-size: 25px;
  88. font-weight: 500;
  89. padding: 6px 12px;
  90. }
  91.  
  92. #target {
  93. width: 345px;
  94. }
  95. </style>
  96. </head>
  97. <body>
  98. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBawDPz1seR1vu-Fw62CDRjmMU6B_oDOZ4&libraries=places.js"></script>
  99. <input id="pac-input" class="controls" type="text" placeholder="Search Box">
  100. <div id="map"></div>
  101. <script>
  102. function initAutocomplete() {
  103. var map = new google.maps.Map(document.getElementById('map'), {
  104. center: {
  105. lat: -33.8688,
  106. lng: 151.2195
  107. },
  108. zoom: 13,
  109. mapTypeId: 'roadmap'
  110. });
  111.  
  112. // Create the search box and link it to the UI element.
  113. var input = document.getElementById('pac-input');
  114. var searchBox = new google.maps.places.SearchBox(input);
  115. map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
  116.  
  117. // Bias the SearchBox results towards current map's viewport.
  118. map.addListener('bounds_changed', function() {
  119. searchBox.setBounds(map.getBounds());
  120. });
  121.  
  122. var markers = [];
  123. // Listen for the event fired when the user selects a prediction and retrieve
  124. // more details for that place.
  125. searchBox.addListener('places_changed', function() {
  126. var places = searchBox.getPlaces();
  127.  
  128. if (places.length == 0) {
  129. return;
  130. }
  131.  
  132. // Clear out the old markers.
  133. markers.forEach(function(marker) {
  134. marker.setMap(null);
  135. });
  136. markers = [];
  137.  
  138. // For each place, get the icon, name and location.
  139. var bounds = new google.maps.LatLngBounds();
  140. places.forEach(function(place) {
  141. if (!place.geometry) {
  142. console.log("Returned place contains no geometry");
  143. return;
  144. }
  145.  
  146. var icons = {
  147. 'Public school': {
  148. icon: 'http://i68.tinypic.com/xcnnz4.png'
  149. },
  150. 'Private school': {
  151. icon: 'http://i67.tinypic.com/2utkz8k.png'
  152. }
  153. };
  154.  
  155. // Create a marker for each place.
  156. markers.push(new google.maps.Marker({
  157. map: map,
  158. icon: icon,
  159. title: place.name,
  160. position: place.geometry.location
  161. }));
  162.  
  163. if (place.geometry.viewport) {
  164. // Only geocodes have viewport.
  165. bounds.union(place.geometry.viewport);
  166. } else {
  167. bounds.extend(place.geometry.location);
  168. }
  169. });
  170. map.fitBounds(bounds);
  171. });
  172. }
  173.  
  174. initAutocomplete();
  175. </script>
  176. </body>
  177. </html>
Add Comment
Please, Sign In to add comment