Advertisement
nasirukun

home.blade.php

Oct 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. @extends('layouts.app')
  2.  
  3. @section('content')
  4. <div class="container">
  5. <div id="map_canvas" style="width:1000px; height:500px;"></div>
  6. </div>
  7. @endsection
  8. @section('js')
  9.  
  10. <script>
  11.  
  12. var map = null;
  13. var radius_circle = null;
  14. var markers_on_map = [];
  15. var geocoder = null;
  16. var infowindow = null;
  17.  
  18. //all_locations is just a sample, you will probably load those from database
  19. var all_locations = [
  20. @foreach ($name as $business)
  21. ['{{$business->name}}',{{$business->latitude}}, {{$business->longitude}}, '{{$business->addressbycoordinate}}'],
  22. @endforeach
  23. ];
  24.  
  25. //initialize map on document ready
  26. $(document).ready(function(){
  27. var latlng = new google.maps.LatLng(40.723080, -73.984340); //you can use any location as center on map startup
  28. var myOptions = {
  29. zoom: 3,
  30. center: latlng,
  31. mapTypeControl: true,
  32. mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  33. navigationControl: true,
  34. mapTypeId: google.maps.MapTypeId.ROADMAP
  35. };
  36. map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  37. geocoder = new google.maps.Geocoder();
  38. google.maps.event.addListener(map, 'click', function(){
  39. if(infowindow){
  40. infowindow.setMap(null);
  41. infowindow = null;
  42. }
  43. });
  44. });
  45.  
  46. function showCloseLocations() {
  47. var i;
  48. var radius_km = $('#radius_km').val();
  49. var address = $('#address').val();
  50. if (radius_circle) {
  51. radius_circle.setMap(null);
  52. radius_circle = null;
  53. }
  54. for (i = 0; i < markers_on_map.length; i++) {
  55. if (markers_on_map[i]) {
  56. markers_on_map[i].setMap(null);
  57. markers_on_map[i] = null;
  58. }
  59. }
  60.  
  61. if (geocoder) {
  62. geocoder.geocode({'address': address}, function (results, status) {
  63. if (status == google.maps.GeocoderStatus.OK) {
  64. if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
  65. var address_lat_lng = results[0].geometry.location;
  66. radius_circle = new google.maps.Circle({
  67. center: address_lat_lng,
  68. radius: radius_km * 1000,
  69. clickable: false,
  70. map: map,
  71. strokeColor: '#FF0000',
  72. strokeOpacity: 0.8,
  73. strokeWeight: 2,
  74. fillColor: '#FF0000',
  75. fillOpacity: 0.35
  76. });
  77. if (radius_circle) map.fitBounds(radius_circle.getBounds());
  78. for (var j = 0; j < all_locations.length; j++) {
  79. var name = all_locations[j][0]
  80. var lat = all_locations[j][1]
  81. var long = all_locations[j][2]
  82. var add = all_locations[j][3]
  83. // var icon1 = all_locations[j][4]
  84. // var photo1 = all_locations[j][5]
  85. // var icon2 = "{{ asset('../resources/assets/images/') }}"
  86. // var icon3 = icon2 + '/' + icon1
  87. // var photo2 = icon2 + '/' + photo1
  88. var marker_lat_lng = new google.maps.LatLng(lat, long);
  89. var distance_from_location = google.maps.geometry.spherical.computeDistanceBetween(address_lat_lng, marker_lat_lng); //distance in meters between your location and the marker
  90. if (distance_from_location <= radius_km * 1000) {
  91. var new_marker = new google.maps.Marker({
  92. position: marker_lat_lng,
  93. map: map,
  94. title: name,
  95.  
  96. });google.maps.event.addListener(new_marker, 'click', function () {
  97. if(infowindow){
  98. infowindow.setMap(null);
  99. infowindow = null;
  100. }
  101. infowindow = new google.maps.InfoWindow({
  102. content: '<div style="color:red">'+name +'</div>' + " is " + distance_from_location + " meters from my location",
  103. size: new google.maps.Size(150,50),
  104. pixelOffset: new google.maps.Size(0, -30),
  105. position: marker_lat_lng,
  106. map: map
  107. });
  108. });
  109. markers_on_map.push(new_marker);
  110. }
  111. (all_locations[j]);
  112. }
  113. } else {
  114. alert("No results found while geocoding!");
  115. }
  116. } else {
  117. alert("Geocode was not successful: " + status);
  118. }
  119. });
  120. }
  121. }
  122. </script>
  123. @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement