2015-11-13 74 views
1

當用戶在jsp頁面中給出日期作爲輸入時,所有緯度&經度被填充到java arraylist中。如何使用java arraylist在jsp中填充Google熱圖LatLng

我與ArrayList中的servlet -

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); 
    } 

如何通過數組列表RLIST填充谷歌地圖經緯度在xyz.jsp?

<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 &地圖提供代碼。我是新來的。

回答

0
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(); 

    }