I'm new to rails and I'm wondering how exactly I could loop these markers. My JS variable "count" is not recognized and I need some help looping through my ruby array or need another solution.
function initMap() {
var mapDiv = document.getElementById('map');
var map = new google.maps.Map(mapDiv, {
center: {lat: 44.540, lng: -78.546},
zoom: 8
});
var total = <%= mapcount %>
var javascriptcount = 0;
var count = 0;
<% arraylat = [] %>
<% arraylng = [] %>
<% mapposttotal.each do |q| %>
<% arraylat << q.lat %>
<% arraylng << q.lng %>
<% end %>
for (; javascriptcount <= total; javascriptcount++) {
var marker = new google.maps.Marker({
position: {lat: <%= arraylat[count] %>, lng: <%= arraylng[count] %>},
map: map,
title: 'Hello World!'
});
count = count + 1;
console.log()
}
var Clicker = document.getElementById('PostIt');
Clicker.addEventListener('click', function() {
window.location='/newpost.html';}, false);
}
<% end %>