Google Maps API使用Rails 4中的Gmaps4rails Gem查看并填充问题
Google Maps API View and populate issues with Gmaps4rails Gem in Rails 4
我正试图按照本教程在这里为我的应用程序添加一个新的脚手架。在视频中,模型名为User,但我的模型名为Reports。我已经到了4:14,但地图加载不正确;请参阅此处查看屏幕截图。它不会放大,只显示蓝色。当我以这样或那样的方式拖动它时,它会变成灰色。
在这一点上,我准确地遵循了教程,但我想知道脚手架是否与我的其他模型不兼容?或者,是引导CSS模板扰乱了这个地图的视图。
问题有两个——视图加载不正确,报告没有在地图上填充。我已经在下面粘贴了一些源代码,如果你想看其他文件,请告诉我,非常感谢你的帮助!
**reports_controller.rb**
class ReportsController < ApplicationController
before_action :set_report, only: [:show, :edit, :update, :destroy]
# GET /reports
# GET /reports.json
def index
@reports = Report.all
@hash = Gmaps4rails.build_markers(@reports) do |report, marker|
marker.lat report.latitude
marker.lng report.longitude
marker.infowindow report.description
end
end
# GET /reports/1
# GET /reports/1.json
def show
end
# GET /reports/new
def new
@report = Report.new
end
# GET /reports/1/edit
def edit
end
# POST /reports
# POST /reports.json
def create
@report = Report.new(report_params)
respond_to do |format|
if @report.save
format.html { redirect_to @report, notice: 'Report was successfully created.' }
format.json { render action: 'show', status: :created, location: @report }
else
format.html { render action: 'new' }
format.json { render json: @report.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /reports/1
# PATCH/PUT /reports/1.json
def update
respond_to do |format|
if @report.update(report_params)
format.html { redirect_to @report, notice: 'Report was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @report.errors, status: :unprocessable_entity }
end
end
end
# DELETE /reports/1
# DELETE /reports/1.json
def destroy
@report.destroy
respond_to do |format|
format.html { redirect_to reports_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_report
@report = Report.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def report_params
params.require(:report).permit(:latitude, :longitude, :address, :description, :photo, :title, :text)
end
end
-*-
**index.html.erb**
<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>
<h1>Listing reports</h1>
<table>
<thead>
<tr>
<th>Latitude</th>
<th>Longitude</th>
<th>Address</th>
<th>Description</th>
<th>Photo</th>
<th>Title</th>
<th>Text</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @reports.each do |report| %>
<tr>
<td><%= report.latitude %></td>
<td><%= report.longitude %></td>
<td><%= report.address %></td>
<td><%= report.description %></td>
<td><%= report.photo %></td>
<td><%= report.title %></td>
<td><%= report.text %></td>
<td><%= link_to 'Show', report %></td>
<td><%= link_to 'Edit', edit_report_path(report) %></td>
<td><%= link_to 'Destroy', report, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Report', new_report_path %>
<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>
是的,这很可能是一个css问题,对gmaps4rails没有什么特别的,只是引导程序和谷歌地图之间已知的不兼容,请参阅gem-doc
您需要添加:
#map img {
max-width: none;
}
#map label {
width: auto; display:inline;
}
相关文章:
- 在指令控制器中使用$attrs时出现问题
- 将PHP变量传递给jQuery时遇到问题
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 参数变量出现ngTable指令问题
- 剑道网格jQuery动画()问题
- 我的jQuery插件参数没有正确启动,遇到了问题
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- TableExport jquery插件:文件名和扩展名问题
- JavaScript Pub/Sub属性访问问题
- JavaScript异步问题
- 如何解决Yii中的页面刷新问题
- Safari(Mac OS)上的jQuery平滑滚动问题
- jqGrid树网格问题
- 使用正则表达式评估电子邮件地址时出现性能问题
- 如何消除代码中的未定义和其他问题
- JavaScript代码问题:我正在将对象转换为数组
- 三星智能电视应用程序;Brightcove示例应用程序远程控制问题
- 外部gem的资产管道编码问题(UTF-8与ASCII-8BIT)
- Thumbs_up Gem,ajax的一个小问题
- Google Maps API使用Rails 4中的Gmaps4rails Gem查看并填充问题