Rails 4 - Gmaps4Rails - Karte wird nicht gerendert
Ich habe Probleme, meine Google Maps in meiner Rails-App zum Laufen zu bringen.
Es hat alles gut funktioniert - ich habe das nächste Feature bearbeitet und bin zurückgekommen, um festzustellen, dass es nicht mehr funktioniert.
Ich habe Modelle für Adresse, Profil und Projekt. Ich verwende die Adresse in jedem Profil und Projekt. In jedem Fall wird die Karte nicht angezeigt.
Die Assoziationen zwischen den Modellen sind:
Adress
belongs_to :addressable, :polymorphic => true
Profi
has_many :addresses, as: :addressable
accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true
Projek
has_many :addresses, as: :addressable
accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true
Die Controller-Show-Funktionen sind:
Adress
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
Profi
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
Projek
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
In meinen Profilen zeige ich:
<%= render partial: "profiles/main_address" %>
n Profilen / Hauptadresse habe ich:
<script src="//maps.google.com/maps/api/js?v=3.18&sensor=false&client=&key=&libraries=geometry&language=&hl=®ion="></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>
Ich habe den gleichen Vorgang in meinem Projektordner, um die Projektadresse anzuzeigen.
n meiner Gem-Datei habe ich:
gem 'google-api-client', '~> 0.7.1', require: 'google/api_client'
gem 'gmaps4rails', '~> 2.1', '>= 2.1.2'
gem 'underscore-rails'
Ich kann nicht herausfinden, warum ich anstelle einer Karte mit der Adresse nur ein Leerzeichen bekomme.
n meinem Konsoleninspektor wird ein roter Fehler angezeigt, der besagt:
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
Beobachten Sie den Fehler, Uncaught ReferenceError: MarkerClusterer ist nicht definiert, der Edelsteinhersteller schlägt Folgendes vor:
rails generate gmaps4rails:install
Wenn ich das versuche, erhalte ich die Fehlermeldung:
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'
Mein Konsoleninspektor zeigt auch eine Reihe von Warnungen in Bezug auf gmaps an:
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
Ich habe einen API-Schlüssel - ich weiß nur nicht, wo ich ihn in meinen Code einfügen soll.
Kann jemand sehen, wie man hilft. Es macht mir nichts aus, wenn ich die Warnprobleme mit Gmaps nicht löse, aber ich möchte wieder dahin zurückkehren, wo ich war, als die Karte angezeigt wurde.