0

ページビューのオブジェクトリストとそれらのオブジェクトを表示しているGoogleマップを表示しようとしています。私はその旅行に属する「ポイント」を表示する「旅行」ビューを持っています。各点には緯度/経度があります。ページが最初に正しくロードし、私は別のページに移動するとき、私は次のようにエラーが発生して起動します。GoogleマップとRageのページネーションを併用する

私のGemfileに
"You have included the Google Maps API multiple times on this page. This may cause unexpected errors." 

message: "not a LatLng or LatLngLiteral: in property lat: not a number" 
name: "InvalidValueError" 

:アプリ/資産/ JavaScriptの/ application.jsで

gem 'gmaps4rails', '2.1.2' 
gem 'underscore-rails' 
gem 'gmaps' 

//= require jquery 
//= require jquery_ujs 
//= require bootstrap 
//= require turbolinks 
//= require underscore 
//= require gmaps/google 
//= require_tree . 

マイコントローラ:

def show 
    @trip = Trip.find(params[:id]) 
    @trip_points = @trip.trip_points 

    @markers = Gmaps4rails.build_markers(@trip_points) do |pt, marker| 
     next if pt.lat.nil? || pt.lon.nil? 
     marker.lat pt.lat 
     marker.lng pt.lon 
    end 
    @markers.reject! { |m| m.empty? } 
    @trip_points = @trip_points.paginate(page: params[:page]) 
    end 

私はすべてポイントを地図上に表示したいと思いますが、ポイントの表示を改ページしています。

マイビュー:

<script src="//maps.google.com/maps/api/js?key=MYAPIKEY" type="text/javascript"></script> 
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script> 

<div class="row"> 
    <aside class="col-md-6"> 
    <%= will_paginate @trip_points %> 
    <ul class="trip_points"> 
     <% if @trip.trip_points.any? %> 
     <%= render @trip_points %> 
     <% else %> 
     <%= render 'trip_points/add_point', last: true, index: 0 %> 
     <% end %> 
    </ul> 
    <%= will_paginate @trip_points %> 

    </aside> 
    <div class="col-md-6"> 
    <div id="map" style='width: 100%; height: 800px; margin-top: 2em;'></div> 
    </div> 
</div> 

<script type="text/javascript"> 
    handler = Gmaps.build('Google'); 
    handler.buildMap({ provider: {}, 
        internal: {id: 'map'}}, 
        function(){ 
    markers = handler.addMarkers(<%= raw @markers.to_json %>); 
    handler.bounds.extendWith(markers); 
    }); 
</script> 

私は私の知る限り、私は私のページに一度GoogleマップAPIを含むよ、言うことができるように部分的_trip_point_.html.erb

を持っています。 .jsはアプリケーション内の別の場所に移動する必要がありますか?この問題を解決するには

答えて

0

私はビュー/レイアウト/ application.html.erb

<head>セクションにビューから最初の2個の <script>のタグを移動
関連する問題