我想在我的Active_admin中集成gmap4rails Api,获取错误gmap这里没有定义代码是: -
map.js
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers([
{
"lat": 0,
"lng": 0,
"picture": {
"url": "http://people.mozilla.com/~faaborg/files/shiretoko/firefoxIcon/firefox-32.png",
"width": 32,
"height": 32
},
"infowindow": "hello!"
}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
包括应用程序布局中Gmaprrails的所有来源
Application.html.erb
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="//maps.google.com/maps/api/js?v=3.23&key= AIzaSyDfo9bkA0O99tPFLgzv41p-nEiIa6qHOfY "></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script>
<!-- only if you need custom infoboxes -->
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'gmaps4rails' %>
<%= gmaps({
"map_options" => { "zoom" => 2, "auto_adjust" => false},
"markers" => { "data" => markers } })%>
<%= yield :javascripts %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
包括application.js中的资产 Application.js
//= require underscore
//= require gmaps/google
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require underscore
//= require_tree .
_map.html.erb
<div style='width: 800px;'>
<div id="map" style='width: 800px; height: 400px;'></div>
admin /branch.rb
@branch = Branch.all
@hash = Gmaps4rails.build_markers(@branch) do |branch, marker|
marker.lat branch.lat
marker.lng branch.lng
end
render partial: 'active_admin/branches/map', locale:{hash: @hash}
end
please help me out !!!
答案 0 :(得分:0)
我认为您应该将应用程序js文件放到Active_admin.js