java - How to use foreach in jstl + javascript? -
i try add pin in google map. have collection ${list}
items coordinate , name. item want put in map. write code:
<script> function initmap() { <c:foreach items="${list}" var="item"> var cairo = {lat: ${item.geometry.lat}, lng: ${item.geometry.lng}}; var map = new google.maps.map(document.getelementbyid('map'), { scalecontrol: true, center: cairo, zoom: 10 }); var infowindow = new google.maps.infowindow; infowindow.setcontent('${item.name}'); </c:foreach> }
but code don't work correct. add in map 1 (last) item collection.
please help.
you may need create marker point map
function initmap() { var cairo =new google.maps.latlng(38.54,77.02); var map = new google.maps.map(document.getelementbyid('map'), { scalecontrol: true, center: cairo, zoom: 10 }); <c:foreach items="${list}" var="item"> var infowindow = new google.maps.infowindow; infowindow.setcontent('${item.name}'); var mylatlng = new google.maps.latlng(${item.geometry.lat}, ${item.geometry.lng}); var marker = new google.maps.marker({ position : mylatlng, map : map, icon : 'img/icon.png' title:${item.name} }); google.maps.event.addlistener(marker, 'click', function() { // map.setzoom(15); // map.setcenter(marker.getposition()); infowindow.open(map, marker); }); </c:foreach> }
Comments
Post a Comment