Guest User

Untitled

a guest
Jan 16th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. set @lat= x; //hardcoded latitude value
  2. set @lng= y; //hardcoded longitude value
  3.  
  4. SELECT *
  5. FROM police_station
  6. ORDER BY ((police_station_lat - @lat)*(police_station_lat - @lat)) +
  7. ((police_station_lng - @lng)*(police_station_lng - @lng)) ASC
  8. LIMIT 1;
  9.  
  10. +------------------+------------------------+-------------------------+--------------------+
  11. |police_station_id |police_station_latitude |police_station_longitude |police_station_name |
  12. +------------------+------------------------+-------------------------+--------------------+
  13. | 17 | 53.289543 | -6.2426 | Dundrum |
  14. +------------------+------------------------+-------------------------+--------------------+
  15.  
  16. /*
  17. * Google Map with marker
  18. */
  19. function initialize() {
  20. var initialLat = $('.search_latitude').val();
  21. var initialLong = $('.search_longitude').val();
  22. initialLat = initialLat?initialLat:53.350140;
  23. initialLong = initialLong?initialLong:-6.266155;
  24.  
  25. var latlng = new google.maps.LatLng(initialLat, initialLong);
  26. var options = {
  27. zoom: 11,
  28. center: latlng,
  29. mapTypeId: google.maps.MapTypeId.ROADMAP
  30. };
  31.  
  32. map = new google.maps.Map(document.getElementById("geomap"), options);
  33.  
  34. geocoder = new google.maps.Geocoder();
  35.  
  36. marker = new google.maps.Marker({
  37. map: map,
  38. draggable: true,
  39. position: latlng
  40. });
  41.  
  42. google.maps.event.addListener(marker, "dragend", function () {
  43. var point = marker.getPosition();
  44. map.panTo(point);
  45. geocoder.geocode({'latLng': marker.getPosition()}, function (results, status) {
  46. if (status == google.maps.GeocoderStatus.OK) {
  47. map.setCenter(results[0].geometry.location);
  48. marker.setPosition(results[0].geometry.location);
  49. $('.search_addr').val(results[0].formatted_address);
  50. $('.search_latitude').val(marker.getPosition().lat());
  51. $('.search_longitude').val(marker.getPosition().lng());
  52. }
  53. });
  54. });
  55.  
  56. }
  57.  
  58. $(document).ready(function () {
  59. //load google map
  60. initialize();
  61.  
  62. /*
  63. * autocomplete location search
  64. */
  65. var PostCodeid = '#search_location';
  66. $(function () {
  67. $(PostCodeid).autocomplete({
  68. source: function (request, response) {
  69. geocoder.geocode({
  70. 'address': request.term
  71. }, function (results, status) {
  72. response($.map(results, function (item) {
  73. return {
  74. label: item.formatted_address,
  75. value: item.formatted_address,
  76. lat: item.geometry.location.lat(),
  77. lon: item.geometry.location.lng()
  78. };
  79. }));
  80. });
  81. },
  82. select: function (event, ui) {
  83. $('.search_addr').val(ui.item.value);
  84. $('.search_latitude').val(ui.item.lat);
  85. $('.search_longitude').val(ui.item.lon);
  86. var latlng = new google.maps.LatLng(ui.item.lat, ui.item.lon);
  87. marker.setPosition(latlng);
  88. initialize();
  89. }
  90. });
  91. });
  92.  
  93. /*
  94. * Point location on google map
  95. */
  96. $('.get_map').click(function (e) {
  97. var address = $(PostCodeid).val();
  98. geocoder.geocode({'address': address}, function (results, status) {
  99. if (status == google.maps.GeocoderStatus.OK) {
  100. map.setCenter(results[0].geometry.location);
  101. marker.setPosition(results[0].geometry.location);
  102. $('.search_addr').val(results[0].formatted_address);
  103. $('.search_latitude').val(marker.getPosition().lat());
  104. $('.search_longitude').val(marker.getPosition().lng());
  105. } else {
  106. alert("Geocode was not successful for the following reason: " + status);
  107. }
  108. });
  109. e.preventDefault();
  110. });
  111.  
  112. //Add listener to marker for reverse geocoding
  113. google.maps.event.addListener(marker, 'drag', function () {
  114. geocoder.geocode({'latLng': marker.getPosition()}, function (results, status) {
  115. if (status == google.maps.GeocoderStatus.OK) {
  116. if (results[0]) {
  117. $('.search_addr').val(results[0].formatted_address);
  118. $('.search_latitude').val(marker.getPosition().lat());
  119. $('.search_longitude').val(marker.getPosition().lng());
  120. }
  121. }
  122. });
  123. });
  124. });
Add Comment
Please, Sign In to add comment