【发布时间】:2015-08-30 13:03:00
【问题描述】:
我是 Ruby on Rails 的新手。 我正在使用 gmaps4rails 和地理编码 gem 开发一个小型地图应用程序。 我的仓库是https://github.com/francisconlm/mapps
现在我正在使用普通代码加载地图:
<div style='width: 800px;'>
<div id="map" style='width: 800px; height: 400px;'></div>
</div>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
我想知道在地图中加载数据库后在地图中添加另一个点的方法。我的目标是在地图中加载数据库(已经工作),然后在同一个地图中加载另一个点(用户所在的位置)。 例如.. 为什么这不起作用?
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers([{<%=raw @hash.to_json %>},{ lat: 43, lng: 3.5}]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
谢谢
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 google-maps google-maps-api-3 gmaps4rails