gpt4 book ai didi

javascript - c :foreach tag is not working for Google map in javascript jsp

转载 作者:行者123 更新时间:2023-12-03 11:17:34 27 4
gpt4 key购买 nike

我必须使用 fatbase 中的纬度和经度值显示 GoogleMap,但它无法使用 c:foreach 标记工作,但我不知道 c:foreach 标记有什么问题。jsp 页面和托管bean 的代码如下:

   <%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
<script type="text/javascript" src="js/jquery-2.1.1.js"></script>

</head>
<body>
<!--<div id="load_me">Current Time :<%= new java.util.Date() %></div>-->
<input type="button" onclick="mapRefresh();" value="Refresh" class="button" />
<div><br/></div>
<div id="map" style="width: 1300px; height: 600px;"></div>

<!-- <script type="text/javascript">
//alert("my alert");
var auto_refresh = setInterval(
function()
{
// alert("alert");
$('#load_me').load('mapview.jsp').fadeIn("slow");
}, 5000); // autorefresh the content of the div after
//every 10000 milliseconds(10sec)
</script>-->
<script type="text/javascript">

//alert("hello");
var locations = [
<c:forEach items="${mapBean.googleMapLocations}" var="googleLocation" varStatus ="status">
['${googleLocation.latitude}', '${googleLocation.longitude}']
<c:if test="${!status.last}">
,
</c:if>
</c:forEach>
];
alert(locations);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng("${mapBean.centerLatitude}", "${mapBean.centerLongitude}"),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][0], locations[i][1]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
<table>
<c:forEach var="googleLocation" items="${mapBean.googleMapLocations}">
<tr><td>${googleLocation.latitude}</td><td>${googleLocation.longitude}</td></tr>
</c:forEach>
CENTER<tr><td>${mapBean.centerLatitude}</td><td>${mapBean.centerLongitude}</td></tr>
</table>

</body>
</html>

Managedbean Code:
public class MapBean implements java.io.Serializable {

private double centerLatitude;
private double centerLongitude;
public java.util.List<Components> getGoogleMapLocations() {
SessionFactory sf = HibernateUtil.getSessionFactory();
Session sess = sf.openSession();
Query q = sess.createQuery("from Components");
java.util.List l = q.list();
sess.close();
return l;
}
}

最佳答案

我想这就是您需要包含在 c:foreach 标记中的内容。

<c:out value="${googleLocation.latitude}', '${googleLocation.longitude}"></c:out> 

关于javascript - c :foreach tag is not working for Google map in javascript jsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27265596/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com