Guest User

Untitled

a guest
Jan 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. def show
  2. @item = Item.find(params[:id])
  3. respond_to do |format|
  4. format.html
  5. format.js { render 'show.js.erb' }
  6. end
  7. @hash = Gmaps4rails.build_markers(@item) do |item, marker|
  8. marker.lat item.latitude
  9. marker.lng item.longitude
  10. marker.picture({
  11. :url => "https://www.google.com/mapfiles/dd-end.png",
  12. :width => 32,
  13. :height => 32
  14. })
  15. marker.infowindow render_to_string(:partial => 'pages/info_page')
  16. end
  17. append_cur_location
  18. end
  19.  
  20. # method to show current location marker on goggle maps
  21. def append_cur_location
  22. @hash << {
  23. :lat=>action[0],
  24. :lng=>action[1],
  25. :picture=> {
  26. :url=> "https://www.google.com/mapfiles/dd-start.png",
  27. :width=> 32,
  28. :height=> 32
  29. }
  30. }
  31. end
  32.  
  33. #method that gets html5 geolocation cookies and splits it
  34. def action
  35. @lat_lng = cookies[:lat_lng].split("|") unless cookies[:lat_lng] == nil
  36. end
  37.  
  38. <div id="map"></div>
  39.  
  40. <script>
  41. handler = Gmaps.build('Google');
  42. handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
  43. markers = handler.addMarkers(<%=raw @hash.to_json %>);
  44. handler.bounds.extendWith(markers);
  45. handler.fitMapToBounds();
  46. handler.getMap().setZoom(15);
  47. });
  48. </script>
  49.  
  50. <script>
  51. var handler = Gmaps.build('Google');
  52. handler.buildMap({ internal: {id: 'map'}}, function(){
  53.  
  54. var start_point = [43.2423, 5.323452];
  55. var end_point = [44.2423, 5.323452];
  56.  
  57. var directionsService = new google.maps.DirectionsService();
  58. var directionsDisplay = new google.maps.DirectionsRenderer();
  59.  
  60. directionsDisplay.setMap(handler.getMap());
  61. var request = {
  62. origin: new google.maps.LatLng(start_point[0], start_point[1]),
  63. destination: new google.maps.LatLng(end_point[0], end_point[1]),
  64. travelMode: google.maps.TravelMode.DRIVING
  65. };
  66.  
  67. directionsService.route(request, function(response, status) {
  68. if (status === google.maps.DirectionsStatus.OK) {
  69. directionsDisplay.setDirections(response);
  70. }
  71. });
  72. });
  73.  
  74. </script>
Add Comment
Please, Sign In to add comment