gpt4 book ai didi

javascript - 谷歌地图 JSP

转载 作者:行者123 更新时间:2023-11-28 02:32:31 26 4
gpt4 key购买 nike

我正在使用 Google map API 和 JSP 创建一个应用程序。我遇到了问题,因为当我向标记添加事件并使用查询字符串传递值时,我不断获得相同的值,而不是标记的实际值。有人可以让我知道我做错了什么吗?

 <%

Query query2 = em.createNamedQuery("Factories.findAll");
List<Factories> factories = query2.getResultList();

for (int i = 0; i < factories.size(); i++) {
Float longitude = factories.get(i).getLongitude();
Float latitude = factories.get(i).getLatitude();
String name = factories.get(i).getName();
Integer id = factories.get(i).getFactoryID();
%>

var marker = new google.maps.Marker({
position: new google.maps.LatLng(<%=latitude%>, <%=longitude%>),
raiseOnDrag:true,
title: "<%=name%>",
clickable:true,
zIndex: <%=id%>,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
window.location = "viewFireworksFactory.jsp?id=" + marker.getZIndex();
});

<% }%>

最佳答案

查看生成的 JavaScript。它将如下所示:

var marker = new google.maps.Marker({
position: new google.maps.LatLng(245, 654),
raiseOnDrag:true,
title: "A",
clickable:true,
zIndex: 1,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
window.location = "viewFireworksFactory.jsp?id=" + marker.getZIndex();
});

var marker = new google.maps.Marker({
position: new google.maps.LatLng(654, 987),
raiseOnDrag:true,
title: "B",
clickable:true,
zIndex: 2,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
window.location = "viewFireworksFactory.jsp?id=" + marker.getZIndex();
});

var marker = new google.maps.Marker({
position: new google.maps.LatLng(985, 2315),
raiseOnDrag:true,
title: "C",
clickable:true,
zIndex: 3,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
window.location = "viewFireworksFactory.jsp?id=" + marker.getZIndex();
});

var marker = new google.maps.Marker({
position: new google.maps.LatLng(6855, 464),
raiseOnDrag:true,
title: "D",
clickable:true,
zIndex: 4,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
window.location = "viewFireworksFactory.jsp?id=" + marker.getZIndex();
});

所以,明确地说,它将重新定义同一标记变量 N 次,覆盖同一变量的先前定义。因此,所有监听器都将获得分配给变量的最后一个对象所引用的标记中的 Z 索引。

关于javascript - 谷歌地图 JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13921744/

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