My MapsController
is
def show
@outlet=OUtlet.all
render 'maps/map'
end
In the view page map.html.erb
, I iterate through each outlet to display their latitude and longitude:
<% @outlet.each do |product| %>
<%= product.latitude %>
<%= product.longitude %>
<% end %>
The resulting coordinates are:
51.503454 -0.119562 51.499633 -0.124755 51.489633 -0.123755 51.479633 -0.122755
Now, I need to pass this array to a JavaScript variable named markers
in the following format:
var markers = [
[ 51.503454,-0.119562],
[ 51.499633,-0.124755],
[ 51.489633,-0.123755],
[ 51.479633,-0.122755]
];
I have attempted solutions like using javascript_tag
and attribute method
but have not been successful. Any assistance on how to properly achieve this would be greatly appreciated.
This marker data format is essential for plotting points on a Google Map.