gmap4railsを使って二点間の距離と時間を取得して表示させたいです。
ruby
1#コントローラ 2 3 def show 4 @requests = @request.building.requests.where.not(id: @request.id, deleted_flg: true) 5 @hash = Gmaps4rails.build_markers(@request) do |request, marker| 6 marker.lat request.latitude 7 marker.lng request.longitude 8 marker.infowindow render_to_string(partial: "layouts/infowindow", locals: { request: request }) 9 end 10 end 11
ruby
1#ビュー 2 3<dl class="row"> 4 <dt class="label">住所</dt> 5 <dd class="data"><%= @request.address %></dd> 6 <a href="javascript:;" onclick="window.open('http://maps.google.co.jp/maps?q='+encodeURI());return false;">Googleマップを開く</a> 7 <% if @hash.present? %> 8 <div id="map" class="request-map"></div> 9 <script type="text/javascript"> 10 handler = Gmaps.build('Google'); 11 handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 12 markers = handler.addMarkers(<%=raw @hash.to_json %>); 13 handler.bounds.extendWith(markers); 14 handler.fitMapToBounds(); 15 handler.getMap().setZoom(14); 16 }); 17 var directionsDisplay = new google.maps.DirectionsRenderer(); 18 var directionsService = new google.maps.DirectionsService(); 19 20 function calcRoute() { 21 var origin = new google.maps.LatLng(33.592865, 130.395141); 22 var destination = new google.maps.LatLng(<%= @request.latitude %>, <%= @request.longitude %>); 23 24 var request = { 25 origin: origin, 26 destination: destination, 27 travelMode: google.maps.TravelMode.TRANSIT 28 }; 29 directionsService.route(request, function(response, status) { 30 if (status == google.maps.DirectionsStatus.OK) { 31 directionsDisplay.setDirections(response); 32 } 33 }); 34 } 35 calcRoute(); // call this anywhere you want 36 directionsDisplay.setMap(handler.getMap()); 37 </script> 38 <% end %> 39 </dl>
このコードでとりあえず二点間のルートを表示することができています。
しかしこのあと、時間と距離を取得して表示する方法がわかりません。
どのように取得し、表示すれば良いのでしょうか?
ご教示の方、何卒よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/10 07:26