我正在尝试使用google静态地图api根据一组经度和纬度点渲染中心地图视图。
google map api提供此网址。
我正在尝试使用数据库中的值并像这样动态插入
<%= image_tag ('http://maps.googleapis.com/maps/api/staticmap?center=#{@location.latitude},#{@location.longitude}&zoom=12&size=400x400&maptype=roadmap&sensor=true')%>
然而,结果图像不断破碎
纬度和经度都是浮点类型属性。
答案 0 :(得分:1)
尝试更改此内容(使用单引号):
'http://maps.googleapis.com/maps/api/staticmap?center=#{@location.latitude},#{@location.longitude}&zoom=12&size=400x400&maptype=roadmap&sensor=true'
到此(带双引号):
"http://maps.googleapis.com/maps/api/staticmap?center=#{@location.latitude},#{@location.longitude}&zoom=12&size=400x400&maptype=roadmap&sensor=true"
单引号按字面解释,因此可能没有渲染插值