Gmaps4rails 未在 rails 4.0.0 Google Maps for Rails 中定义,我正在关注本教程“ http://rubydoc.info/gems/gmaps4rails/2.0.4/frames ”
1) Gemfile
gem 'gmaps4rails'
2) HTML on view page
<div style='width: 800px;'>
<div id="map" style='width: 800px; height: 400px;'></div>
</div>
3) on view page
<script src="//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
You'll require underscore.js too, see here: underscorejs.org/
3) Javascript source code
If you have the asset pipeline, add this:
//= require underscore
//= require gmaps/google
If you don't have asset pipeline, you'll need to import the js OR coffee files:
rails g gmaps4rails:copy_js
rails g gmaps4rails:copy_coffee
4) Javascript code:
Create your map:
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers([
{
"lat": 0,
"lng": 0,
"picture": {
"url": "https://addons.cdn.mozilla.net/img/uploads/addon_icons/13/13028-64.png",
"width": 36,
"height": 36
},
"infowindow": "hello!"
}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
但是当我检查萤火虫时,它显示“ Gmaps is not defined ” Ruby 2.0.0 rails 4.0.0 gmaps4rails 2.0.3
有什么建议请回复......