Google maps 如何在JSP循环中定义动态变量?
我已经编写了以下代码来显示标记,并有相应的信息窗口来显示警察局的名称。 policestation类具有名称、纬度和经度Google maps 如何在JSP循环中定义动态变量?,google-maps,jsp,for-loop,dynamic-variables,Google Maps,Jsp,For Loop,Dynamic Variables,我已经编写了以下代码来显示标记,并有相应的信息窗口来显示警察局的名称。 policestation类具有名称、纬度和经度 <script> function initialize() { var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/'; var myCenter = new google.maps.LatLng(28.65
<script>
function initialize()
{
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var myCenter = new google.maps.LatLng(28.6523605,77.0910645);
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
var mapProp = {
center: myCenter,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
var marker = [];
var info= [];
<%
ArrayList<PoliceStation> stationList = new PoliceStation().loadclass();
for (int i=0 ; i < stationList.size() ; i++) {
%>
var pos = new google.maps.LatLng(
<%= stationList.get(i).getLatitude()%>,
<%= stationList.get(i).getLongitude()%>
);
marker = new google.maps.Marker({
position: pos,
map: map
});
marker.setMap(map);
var MarkerContent = "<div class=\"marker\">" +
"<h2>"+ "<%=stationList.get(i).getstationName()%>"
+"</h2>"+
"</div>";
info=new google.maps.InfoWindow();
info.setOptions({
content: MarkerContent,
size: new google.maps.Size(50, 50),
position: pos
});
google.maps.event.addListener(marker, 'click', function () {
info.setOptions({
content: MarkerContent
});
info.open(map, marker);
});
<%
}
%>
然而,我正在寻找一种解决方案,以动态清晰地定义每个变量名。
例如,将每次迭代时递增的计数器值附加到每个标记和信息变量。
请不要提供JSTP解决方案。寻找一个特定的JSP解决方案出乎意料地非常容易。。。 JSP基本上用于动态打印HTML。 因此,与其使用标记变量作为
var marker = new google.maps.Marker({
position: pos,
map: map
});
使用-
不需要
var marker = new google.maps.Marker({
position: pos,
map: map
});
var <%out.print("marker"+i);%> = new google.maps.Marker({
position: pos,
map: map
});
var <%out.print("marker["+i+"]");%> = new google.maps.Marker({
position: pos,
map: map
});
info.setOptions({
content: MarkerContent
});