Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <?php
  3. $places = ['restaurant', 'store', 'park', 'museum', 'church', 'mosque', 'bank', 'pharmacy', 'airport', 'beach', 'hospital'];
  4. ?>
  5. <html>
  6. <head>
  7. <title>Place searches</title>
  8. <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  9. <meta charset="utf-8">
  10. <style>
  11. html, body, #map-canvas {
  12. height: 100%;
  13. margin: 0px;
  14. padding: 0px
  15. }
  16. #feedback { font-size: 1.3em; }
  17. #type .ui-selecting { background: #B4CDCD; }
  18. #type .ui-selected { background: #5F9F9F; color: white; border: 1px solid black;}
  19. #type { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  20. #type li { margin: 3px; padding: 0.4em; font-size: 1.3em; height: 18px; }
  21. </style>
  22. <script src="jquery-1.11.1.js"></script>
  23. <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
  24. <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  25. <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  26. <script type="text/javascript" src="https://www.google.com/jsapi" ></script>
  27. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
  28.  
  29. <script>
  30. var map;
  31. var infowindow;
  32. var placeslatlng = [];
  33. var point;
  34. var lat = 0;
  35. var lng = 0;
  36. $(document).ready(function () {
  37. // $("#type li").click(function () {
  38. // initialize($(this).html());
  39. // });
  40. //
  41. $(".ui-widget-content").hover(function () {
  42. $(this).css("background", "#B4CDCD");
  43. }, function () {
  44. $(this).css("background", "#000000");
  45. });
  46. $("#type").selectable({
  47. stop: function () {
  48. initialize($(".ui-selected").html());
  49. }
  50. });
  51. $("#type").hover(function () {
  52. $(this).css("cursor", "pointer");
  53. }, function () {
  54. $(this).css("cursor", "none");
  55. });
  56. $("#searchTextField").keydown(function (e) {
  57. if ((e.keyCode || e.which) == 13) {
  58. var address = $("#searchTextField").val();
  59.  
  60. $.ajax({
  61. url: "https://maps.googleapis.com/maps/api/geocode/json?address=" + address,
  62. dataType: "json",
  63. success: function (data) {
  64. console.log("https://maps.googleapis.com/maps/api/geocode/json?address=" + address);
  65. console.log(data.results[0].geometry.location);
  66. lat = data.results[0].geometry.location.lat;
  67. lng = data.results[0].geometry.location.lng;
  68. var mapProp = {
  69. center: new google.maps.LatLng(lat, lng),
  70. zoom: 14,
  71. mapTypeId: google.maps.MapTypeId.ROADMAP
  72. };
  73. map = new google.maps.Map(document.getElementById("map-canvas"), mapProp);
  74. var request = {
  75. location: new google.maps.LatLng(lat, lng),
  76. radius: 1000,
  77. types: [place]
  78. };
  79. infowindow = new google.maps.InfoWindow();
  80. var service = new google.maps.places.PlacesService(map);
  81. service.nearbySearch(request, callback);
  82. $("#place-table").html("");
  83. }
  84. });
  85.  
  86.  
  87. }
  88. });
  89. });
  90.  
  91. function initialize(place) {
  92. $.get("http://ipinfo.io", function (response) {
  93. var geocoder = new google.maps.Geocoder();
  94. geocoder.geocode({'address': response.city}, function (results, status) {
  95. if (status == google.maps.GeocoderStatus.OK) {
  96. if (lat == 0 && lng == 0) {
  97. console.log(lat + " " + lng);
  98. lat = results[0].geometry.location.lat();
  99. lng = results[0].geometry.location.lng();
  100. }
  101. point = new google.maps.LatLng(lat, lng);
  102. map = new google.maps.Map(document.getElementById('map-canvas'), {
  103. center: point,
  104. zoom: 15
  105. });
  106. var defaultBounds = new google.maps.LatLngBounds(
  107. new google.maps.LatLng(42.0000, 21.4333),
  108. new google.maps.LatLng(42.0111, 21.1234));
  109.  
  110. var input = document.getElementById('searchTextField');
  111.  
  112. var searchBox = new google.maps.places.SearchBox(input, {
  113. bounds: defaultBounds
  114. });
  115. var request = {
  116. location: point,
  117. radius: 1000,
  118. types: [place]
  119. };
  120. infowindow = new google.maps.InfoWindow();
  121. var service = new google.maps.places.PlacesService(map);
  122. service.nearbySearch(request, callback);
  123. }
  124. });
  125. }, "jsonp");
  126.  
  127.  
  128.  
  129.  
  130.  
  131. }
  132.  
  133. function callback(results, status) {
  134. if (status == google.maps.places.PlacesServiceStatus.OK) {
  135. $("#place-table").html("");
  136. placeslatlng = [];
  137. for (var i = 0; i < results.length; i++) {
  138. $("#place-table").append("<tr><td>" + "<img src='" + results[i].icon + "'/>" + "</td><td>" + results[i].name + "</td></tr>");
  139. placeslatlng.push(results[i]);
  140. createMarker(results[i]);
  141. }
  142. $("#place-table tr").click(function () {
  143. $(this).css("background", "lightgrey");
  144. $("#place-table tr").not($(this)).css("background", "none");
  145. idx = $(this).index();
  146. console.log(placeslatlng[idx]);
  147. lat = placeslatlng[idx].geometry.location.k;
  148. lng = placeslatlng[idx].geometry.location.D;
  149. //
  150. var pyrmont = new google.maps.LatLng(lat, lng);
  151. map = new google.maps.Map(document.getElementById('map-canvas'), {
  152. center: pyrmont,
  153. zoom: 15
  154. });
  155. //
  156. createMarker(placeslatlng[idx]);
  157. });
  158. }
  159. }
  160.  
  161. function createMarker(place) {
  162. var placeLoc = place.geometry.location;
  163. var marker = new google.maps.Marker({
  164. map: map,
  165. position: place.geometry.location
  166. });
  167.  
  168. google.maps.event.addListener(marker, 'click', function () {
  169. infowindow.setContent(place.name);
  170. infowindow.open(map, this);
  171. });
  172. }
  173.  
  174. google.maps.event.addDomListener(window, 'load', initialize);
  175.  
  176. </script>
  177. </head>
  178. <body>
  179. <div style="float: left;width: 15%;height: 100%">
  180. <ul id="type">
  181. <?php
  182. foreach ($places as $place) {
  183. ?>
  184. <li><?php echo $place ?></li>
  185. <?php
  186. }
  187. ?>
  188. </ul>
  189. </div>
  190. <input id="searchTextField" type="text" size="50" style="position:absolute;margin-left:10%;float:left;z-index: 1">
  191. <div style="float: left;margin-left:15%;width: 60%;height: 100% ;position:absolute" id="map-canvas"></div>
  192. <div id="place" style="float: left;width: 25%;height: 100%;position:absolute;margin-left:75%;overflow: scroll">
  193. <table id="place-table">
  194.  
  195. </table>
  196. </div>
  197. </body>
  198. </html>
  199. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement