0

This answer is working fine with hardcoded locations but I want to use my <c:forEach var="location" items="${latlng.rows}"> and populate the locations variable from database with <sql:setDataSource> tag. I have 6 rows in my database table but I get only the last marker from database on the map.

This is hardcoded version which works fine:

<script type="text/javascript">
    var locations = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.923036, 151.259052, 5],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 1]
    ];

.....
</script>

Here is my code which doesn't work:

<script type="text/javascript">
   var locations = [
        <c:forEach var="location" items="${latlng.rows}">
            [<c:out value='${location.name}'/>,
             <c:out value='${location.latitude}'/>, 
             <c:out value='${location.longitude}'/>,
             <c:out value='${location.id}'/> ],
        </c:forEach>        
    ];
.....
</script>

How can I get output from forEach items row to works like hardcoded version?

Community
  • 1
  • 1
oxyt
  • 1,816
  • 3
  • 23
  • 33

1 Answers1

0

I don't know if this is the proper answer but this worked for me, in case if anyone else encounter the same problem.

    var locations = [];
        <c:forEach var="location" items="${latlng.rows}">
            locations.push(["${location.name}",
                            "${location.latitude}",
                            "${location.longitude}",
                            "${location.id}"]);
        </c:forEach>
oxyt
  • 1,816
  • 3
  • 23
  • 33