【问题标题】:How to populate google heatmap LatLng by java arraylist in jsp如何在jsp中通过java arraylist填充谷歌热图LatLng
【发布时间】:2016-02-15 05:30:58
【问题描述】:

当用户在jsp页面中输入日期时,所有的纬度和经度都会被填充到java arraylist中。

我的 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 提供代码。我是新手。

【问题讨论】:

    标签: java json jsp servlets google-maps-api-3


    【解决方案1】:
    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();
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多