Advertisement
Guest User

Untitled

a guest
Feb 13th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. <?php
  2. echo $this->Html->script('https://maps.googleapis.com/maps/api/js?sensor=false', array('inline' => false));
  3. ?>
  4.  
  5. <div class="alignCenter bottomBorder marginBot36">
  6. <div class="widthContainer padBot18 padTopt18">
  7. <?php echo $this->Html->image('icon-round-marker-pink.png', array('class'=>'midAlignImg'));?>
  8. </div>
  9. <div class="widthContainer fontTwentySeven padBot18">
  10. Which locations do you cover?
  11. </div>
  12. <div class="singleColForm alignLeft fontFourteen" style="border:none">
  13. <div class="left"><?php echo $this->Html->image('mileradius.png');?></div>
  14. <div class="right" id="sliderHolder">
  15. <div id="slider"></div>
  16. </div>
  17. <div style="clear:both;height:18px"></div>
  18. <div id="map-canvas"></div>
  19. <div id="map-numOf-miles" class="alignCenter fontPurple fontNineteen">0 Miles</div>
  20. </div>
  21. <div class="addButton strong">ADD</div>
  22. </div>
  23. <?php // hidden inputs for locations
  24. echo $this->Form->hidden('miles', array('id'=>'miles'));
  25. echo $this->Form->hidden('location', array('id'=>'location'));
  26. ?>
  27.  
  28.  
  29.  
  30.  
  31. <script type="text/javascript">
  32. $(document).ready(function() {
  33.  
  34.  
  35. //User clicks to add location
  36. $(".addButton").click(function() {
  37. $.post( "<?php echo $this->webroot;?>locations/add", { name: "John", time: "2pm" })
  38. .done(function( data ) {
  39. alert( "Data Loaded: " + data );
  40. });
  41. });
  42.  
  43. //Google Maps
  44. var userLocation = "London";
  45. var geocoder = new google.maps.Geocoder();
  46. var circle;
  47. var latLng;
  48. var marker;
  49.  
  50. $( "#slider" ).slider({
  51. slide: function(event, ui) {
  52. $("#map-numOf-miles").html(ui.value+' Miles');
  53. $("#miles").val(ui.value);
  54. circle.setRadius(ui.value/0.0621371192*100);
  55. }
  56. });
  57.  
  58. //Google Maps
  59. function initialize() {
  60. var styles = [
  61. {
  62. stylers: [
  63. { hue: "#00ffe6" },
  64. { saturation: -20 }
  65. ]
  66. }
  67. ];
  68.  
  69. geocoder.geocode( {"address": userLocation}, function(results, status) {
  70. if (status == google.maps.GeocoderStatus.OK) {
  71. latLng = results[0].geometry.location;
  72. //alert (latLng);
  73. var mapOptions = {
  74. center: latLng,
  75. zoom: 6,
  76. styles: styles,
  77. mapTypeId: google.maps.MapTypeId.ROADMAP
  78. };
  79.  
  80. map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
  81.  
  82. marker = new google.maps.Marker({
  83. map: map,
  84. position: latLng,
  85. draggable: true
  86. });
  87.  
  88. circle = new google.maps.Circle({
  89. map: map,
  90. radius: 0, //your radius in meters
  91. strokeColor: '#d12d87',
  92. strokeOpacity: 0.35,
  93. strokeWeight: 2,
  94. fillColor: '#d12d87',
  95. fillOpacity: 0.35,
  96. center: latLng
  97. });
  98.  
  99.  
  100. $("#location").val(results[0].geometry.location);
  101. google.maps.event.addListener(marker, "dragend", function(){
  102. var position = marker.getPosition();
  103. map.setCenter(position);
  104. //update the hidden form with the new location
  105. $("#location").val(position.lat() + " ," + position.lng());
  106. //reverse geocode the latlng to get human readable address
  107. var latlng = new google.maps.LatLng(position.lat(), position.lng());
  108. geocoder.geocode({'latLng': latlng}, function(results, status) {
  109. if (status == google.maps.GeocoderStatus.OK) {
  110. if (results[1]) {
  111. alert(results[1].formatted_address);
  112. map.setZoom(11);
  113. marker = new google.maps.Marker({
  114. position: latlng,
  115. map: map
  116. });
  117. infowindow.setContent(results[1].formatted_address);
  118. infowindow.open(map, marker);
  119. } else {
  120. alert('No results found');
  121. }
  122. } else {
  123. alert('Geocoder failed due to: ' + status);
  124. }
  125. });
  126.  
  127. });
  128. google.maps.event.addListener(marker, "drag", function(){
  129. circle.setCenter(marker.getPosition());
  130. });
  131. } else {
  132. alert("Geocode failed. Please edit your address (top of the page) and try again.");
  133. }
  134. });
  135. }
  136. google.maps.event.addDomListener(window, "load", initialize);
  137.  
  138.  
  139. });
  140. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement