Rails 4 – Gmaps4Rails – 地图不会渲染

我正努力让我的谷歌地图在我的Rails应用程序中运行。

一切正常 – 我继续研究下一个function,并回来发现它不再适用。

我有地址,个人资料和项目的模型。 我在每个配置文件和项目中使用地址在每种情况下,地图都不会显示。

模型之间的关联是:

地址

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 

控制器显示的function是:

地址

 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 

在我的个人资料展示中,我有:

   

在个人资料/主要地址,我有:

     
handler = Gmaps.build('Google'); handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ markers = handler.addMarkers(); handler.bounds.extendWith(markers); handler.fitMapToBounds(); handler.getMap().setZoom(8); });

我在我的项目文件夹中有相同的过程来显示项目地址。

在我的gem文件中,我有:

 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 

谷歌搜索错误,Uncaught ReferenceError:MarkerClusterer未定义,gem制造商建议运行:

 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' 

我的控制台检查器还显示了许多与gmaps相关的警告,如:

 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 

我有一个api密钥 – 我只是不知道在我的代码中把它放在哪里。

任何人都可以看到如何帮助。 我不介意我不解决Gmaps的警告问题,但我确实想回到地图显示时的状态。

所以你的问题是这两行:

   

有人直接从Google SVN引用了markerclusterermarkerclusterer库(这是一种不好的做法),几周之前这个库被移到了Github。

您可以从此处下载infobox库到您的项目并参考infobox_packed.js文件:

  

同样,您可以在此处下载标记群集库。 小心:对于标记群集,您将需要srcimages

请阅读这个问题和答案 ,也就是这一个 ,也许这个 。 我强烈建议你阅读问题中的所有答案,因为其中一些包含错误的解决方案(来自新github位置的参考库,而不是将它们下载到你的项目并从那里引用它们是不好的做法)