将浮点数插入到Url中

时间:2014-01-04 11:57:02

标签: ruby-on-rails google-maps-api-3 ruby-on-rails-4

我正在尝试使用google静态地图api根据一组经度和纬度点渲染中心地图视图。

google map api提供此网址。

http://maps.googleapis.com/maps/api/staticmap?center=40.689249,-74.044500&zoom=12&size=400x400&maptype=roadmap&sensor=true

我正在尝试使用数据库中的值并像这样动态插入

<%= image_tag ('http://maps.googleapis.com/maps/api/staticmap?center=#{@location.latitude},#{@location.longitude}&zoom=12&size=400x400&maptype=roadmap&sensor=true')%>

然而,结果图像不断破碎

注意:

纬度和经度都是浮点类型属性。

1 个答案:

答案 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"

单引号按字面解释,因此可能没有渲染插值