RoR - 谷歌地图中的折线

时间:2010-04-15 06:15:24

标签: ruby-on-rails ruby google-maps

我正在使用Ym4r并希望在我的地图上添加折线。

这有效:

polyline = GPolyline.new([[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]],"#ff0000",3,1.0)
@map.record_init @map.add_overlay(polyline)

但这不是:

polystring = "[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]"
polyline = GPolyline.new([polystring],"#ff0000",3,1.0)
@map.record_init @map.add_overlay(polyline)

知道为什么吗? 问候 Arwed

1 个答案:

答案 0 :(得分:1)

从给出的代码中可以看出,GPolyline.new接受第一个参数作为数组(数组的aray),所以试试这个

polystring = [[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]]
polyline = GPolyline.new(polystring,"#ff0000",3,1.0)
@map.record_init @map.add_overlay(polyline)

   polystring = "[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]"
   arr1= [polystring]
   arr2= [[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]]

then arr1[0] = "[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]" where as 
     arr2[0] = [27.4037755983,89.4263076782]