Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def show
- @item = Item.find(params[:id])
- respond_to do |format|
- format.html
- format.js { render 'show.js.erb' }
- end
- @hash = Gmaps4rails.build_markers(@item) do |item, marker|
- marker.lat item.latitude
- marker.lng item.longitude
- marker.picture({
- :url => "https://www.google.com/mapfiles/dd-end.png",
- :width => 32,
- :height => 32
- })
- marker.infowindow render_to_string(:partial => 'pages/info_page')
- end
- append_cur_location
- end
- # method to show current location marker on goggle maps
- def append_cur_location
- @hash << {
- :lat=>action[0],
- :lng=>action[1],
- :picture=> {
- :url=> "https://www.google.com/mapfiles/dd-start.png",
- :width=> 32,
- :height=> 32
- }
- }
- end
- #method that gets html5 geolocation cookies and splits it
- def action
- @lat_lng = cookies[:lat_lng].split("|") unless cookies[:lat_lng] == nil
- end
- <div id="map"></div>
- <script>
- handler = Gmaps.build('Google');
- handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
- markers = handler.addMarkers(<%=raw @hash.to_json %>);
- handler.bounds.extendWith(markers);
- handler.fitMapToBounds();
- handler.getMap().setZoom(15);
- });
- </script>
- <script>
- var handler = Gmaps.build('Google');
- handler.buildMap({ internal: {id: 'map'}}, function(){
- var start_point = [43.2423, 5.323452];
- var end_point = [44.2423, 5.323452];
- var directionsService = new google.maps.DirectionsService();
- var directionsDisplay = new google.maps.DirectionsRenderer();
- directionsDisplay.setMap(handler.getMap());
- var request = {
- origin: new google.maps.LatLng(start_point[0], start_point[1]),
- destination: new google.maps.LatLng(end_point[0], end_point[1]),
- travelMode: google.maps.TravelMode.DRIVING
- };
- directionsService.route(request, function(response, status) {
- if (status === google.maps.DirectionsStatus.OK) {
- directionsDisplay.setDirections(response);
- }
- });
- });
- </script>
Add Comment
Please, Sign In to add comment