Skip to content

Commit

Permalink
Add bus route maps
Browse files Browse the repository at this point in the history
  • Loading branch information
yamamuteki committed Apr 23, 2016
1 parent 62e0f0d commit 90209fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/bus_route_infos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class BusRouteInfosController < ApplicationController
def show
@bus_route_info = BusRouteInfo.preload(:bus_stops).find(params[:id])
@hash = Gmaps4rails.build_markers(@bus_route_info.bus_stops) do |bus_stop, marker|
marker.lat bus_stop.latitude
marker.lng bus_stop.longitude
marker.infowindow bus_stop.name
end
end
end
9 changes: 9 additions & 0 deletions app/views/bus_route_infos/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
<li><%= link_to "#{bus_stop.name}", bus_stop_path(bus_stop) %></li>
<% end %>
</ol>
<div id="map" class="map"></div>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: { draggable: false, scrollwheel: false, MinZoom:15 }, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
<%= link_to '戻る', 'javascript:history.back()', class: 'btn btn-default' %>

0 comments on commit 90209fe

Please sign in to comment.