I'm trying to set multiple markers using this example in rails. The basic ( only HTML) version works fine.
I have a Family model with latitude and longitude fields as type Float.I'm using Mongoid.

Now In my map.html.erb I do (I have changed the beaches var to locations)

var locations = <%= @family %>;  

In my controller I have:

def map
    @family=[[24.1411, 78.7935]]     #This works fine (shows markers)
    lat=Family.last.latitude
    lng=Family.last.longitude
    @family=[[lat,lng]]          #This doesn't work (doesn't show marker)
end  

What is wrong here?

In both the cases the rendered locations var is equal to [[24.1411, 78.7935]] as below

enter image description here

I'm not using gmaps4rails gem because it doesn't provide reverse geocoding.

有帮助吗?

解决方案

Replace:

var locations = <%= @family %>;

with:

var locations = <%= raw @family.to_json %>;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top