当用户在 jsp 页面中输入日期时,所有纬度和经度都会填充到 java 数组列表中。
我的 servlet 与 arraylist -
String startDate=request.getParameter("from");
String endDate=request.getParameter("to");
List<LocInfo> rList=new ArrayList<LocInfo>();
try {
rList=LocBO.retrieveAll(startDate,endDate);
request.setAttribute("Map", rList);
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
RequestDispatcher rx=request.getRequestDispatcher("xyz.jsp");
rx.forward(request, response);
}
如何传递 arraylist rList 来填充 xyz.jsp 中的谷歌地图 LatLng?
<script>
var map, heatmap;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: {lat: 37.775, lng: -122.434},
mapTypeId: google.maps.MapTypeId.SATELLITE
});
heatmap = new google.maps.visualization.HeatmapLayer({
data: getPoints(),
map: map
});
}
function getPoints() {
return [
new google.maps.LatLng(37.782551, -122.445368),
new google.maps.LatLng(37.751266, -122.403355)
];
}
</script>
JSON 是唯一的解决方案吗?如果是,请根据此 servlet/jsp 和 map 提供代码。我对此很陌生。
最佳答案
var gmarkers = [];
function addMarker(data, imageIcon) {
if (data != undefined && data.length) {
for (var i = 0; i < data.length; ++i) {
var marker = new google.maps.Marker({
position: {
lat: data[i].Latitude,
lng: data[i].Longitude
},
map: map,
icon: image
});
gmarkers[data[i].Id] = marker;
}
}
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: {lat: 63.2703467, lng: -6.9219481 },
mapTypeId: google.maps.MapTypeId.SATELLITE
});
addMarker();
}
关于java - 如何在jsp中通过java arraylist填充google heatmap LatLng,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33696049/