2016-06-01 16 views
0

GoogleマップをRailsアプリで使用するには苦労しています。Rails 4 - Gmaps4Rails - 地図はレンダリングされません

これはうまくいきました。私は次の機能に取り掛かり、機能しなくなったことを確認するために戻ってきました。

住所、プロフィール、プロジェクトのモデルがあります。私はそれぞれのプロファイルとプロジェクトでアドレスを使用するそれぞれの場合、地図は表示されません。モデル間の

団体は以下のとおりです。

住所

belongs_to :addressable, :polymorphic => true 

プロフィール

has_many :addresses, as: :addressable 
    accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true 

プロジェクト

has_many :addresses, as: :addressable 
    accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true 

コントローラショーの機能は次のとおりです私のプロフィールには

住所

def create 
    @address = Address.new(address_params) 
    authorize @address 

    respond_to do |format| 
     if @address.save 
     format.html { redirect_to @address, notice: 'Address was successfully created.' } 
     format.json { render :show, status: :created, location: @address } 
     else 
     format.html { render :new } 
     format.json { render json: @address.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

プロフィール

def show 
    # debugger 
    @profile = Profile.includes(:industries).find(params[:id]) 
    # @organisation = Organisation.find(params[:organisation_id]) 
    # @profiles = @organisation.profiles 
    @addresses = @profile.addresses 

     @hash = Gmaps4rails.build_markers(@addresses) do |address, marker| 
     marker.lat address.latitude 
     marker.lng address.longitude 
     marker.infowindow address.full_address 
     end 
    end 

プロジェクト

def show 
    @invite = Invite.new 
    @project = Project.find(params[:id]) 
    @addresses = @project.addresses 

     @hash = Gmaps4rails.build_markers(@addresses) do |address, marker| 
     marker.lat address.latitude 
     marker.lng address.longitude 
     marker.infowindow address.full_address 

     end 

は、私が持っている、を示しています。

<%= render partial: "profiles/main_address" %> 
012プロファイル/メインアドレスで、私が持っている:

<script src="//maps.google.com/maps/api/js?v=3.18&sensor=false&client=&key=&libraries=geometry&language=&hl=&region="></script> 
<script src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js"></script> 
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js' type='text/javascript'></script> <!-- only if you need custom infoboxes --> 

<div style='width: 800px;'> 
    <div id="map" style='width: 800px; height: 400px;'></div> 
</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(8); 
}); 
</script> 

私は、プロジェクトのアドレスを示すための私のプロジェクトフォルダ内の同じプロセスを持っています。私の宝石ファイルで

は私が持っている:私はちょうど住所を示すマップの代わりに空白を取得する理由

gem 'google-api-client', '~> 0.7.1', require: 'google/api_client' 
gem 'gmaps4rails', '~> 2.1', '>= 2.1.2' 
gem 'underscore-rails' 

私が把握することはできません。

primitives.self-5b8a3a6….js?body=1:16 Uncaught ReferenceError: MarkerClusterer is not definedGmaps.Google.Primitives @ primitives.self-5b8a3a6….js?body=1:16Gmaps.Objects.Handler.Handler.setPrimitives @ handler.self-2f220ca….js?body=1:122Handler @ handler.self-2f220ca….js?body=1:8Gmaps.build @ base.self-8dd1d1a….js?body=1:9(anonymous function) @ 14:760 

エラーをグーグルで、キャッチされないにReferenceError:MarkerClustererが定義されていない、宝石メーカーが実行されていることを示唆している:私のコンソールインスペクタで

、私が言う赤いエラーを見ることができます

rails generate gmaps4rails:install 

試してみると、次のエラーが表示されます。

Running via Spring preloader in process 93390 
Could not find generator 'gmaps4rails:install'. Maybe you meant 'paper_trail:install', 'gmaps4rails:copy_js' or 'responders:install' 

マイコンソールのインスペクタ私はちょうど私のコードでそれを置くことを知っていない - 私はAPIキーを持っている

Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys 
util.js:220 Google Maps API warning: RetiredVersion https://developers.google.com/maps/documentation/javascript/error-messages#retired-version 
util.js:220 Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required 
util.js:220 Google Maps API warning: InvalidClientId https://developers.google.com/maps/documentation/javascript/error-messages#invalid-client-id 
util.js:220 Google Maps API warning: InvalidKey https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key 
14:1 Failed to decode downloaded font: http://localhost:3000/assets/flaticon-080b09d3f53cb13c2f9d9a4c53ad7a71206bd8e2390c3e18d2b42ce9388a49a6.woff 

:としてもgmapsに関連する警告の数を示しています。

誰でも手助けをすることができます。私はGmapsでの警告の問題を解決しなければ気にしませんが、マップが表示されたときの私の位置に戻っていきたいと思います。

答えて

0

だからあなたの問題は、これらの2本の線である:

<script src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js"></script> 
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js' type='text/javascript'></script> 

誰かが(悪い習慣である)GoogleのSVNから直接markerclustererinfoboxライブラリを参照すると、ライブラリは数週間前のGithubに移されました。あなたはhereからプロジェクトにinfoboxライブラリをダウンロードして、infobox_packed.jsファイル参照することができ

:同様

<script src='path/to/infobox_packed.js' type='text/javascript'></script> 

を、あなたは、マーカークラスタラライブラリhereをダウンロードすることができます。注意:マーカクラスタでは、srcimagesの両方が必要です。

SO question and answers、またthis one、おそらくthis oneをお読みください。それらのいくつかは、(代わりにあなたのプロジェクトにそれらをダウンロードし、悪い習慣があるからそれらを参照する新しいgithubの場所から参照ライブラリ、)悪いのソリューションが含まれているように私は強くこんにちはマテイ

+0

、質問内のすべての答えを読むためにあなたをアドバイス、ありがとう。リポジトリを複製してプロジェクト内で参照するという悪い習慣を意味するのか、githubファイルを参照するのは悪い習慣です。他の投稿はgithubのリファレンスに頼るのが悪いことを示唆しています。 – Mel

+0

はい。あなたはgithubから参照すべきではありません。レポをクローニングし、それらを参照することは絶対に大丈夫です。それが私が他の答えをリンクさせた主な理由です、私はあなたが私が何を意味してうれしいかうれしいです:) –

関連する問題