Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用使用jsp for google maps从数据库检索的值填充javascript数组_Javascript_Jsp_Google Maps Api 3 - Fatal编程技术网

使用使用jsp for google maps从数据库检索的值填充javascript数组

使用使用jsp for google maps从数据库检索的值填充javascript数组,javascript,jsp,google-maps-api-3,Javascript,Jsp,Google Maps Api 3,嗨,我正在尝试从数据库中检索IP地址,并将其转换为纬度和经度,这很好。我想将它们发送到一个javascript数组,并将它们绘制在谷歌地图上,我发现这很难做到。我刚才的代码绘制了谷歌地图中的最后一个值。如何将所有值发送到数组 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import

嗨,我正在尝试从数据库中检索IP地址,并将其转换为纬度和经度,这很好。我想将它们发送到一个javascript数组,并将它们绘制在谷歌地图上,我发现这很难做到。我刚才的代码绘制了谷歌地图中的最后一个值。如何将所有值发送到数组

  <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@ page
        import="javaQuery.j2ee.*" 
        import="javaQuery.importClass.javaQueryBundle"
        import="com.ayu.UI.ConnectionManager"
        import="java.sql.*"
        %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>GeoLocation</title>
    <script src="http://maps.google.com/maps/api/js?sensor=false" 
              type="text/javascript"></script>
    </head>
    <body>
    <%! 
    Connection con = null; 
    ResultSet rs = null; 
    Statement stmt = null;
    GeoLocation $gl;
    String ipaddress = null;
    Double lat;
    Double lon;
    %>
    <%
    String query="select * from iptable";
    con = ConnectionManager.getConnection();
    try {
        stmt=con.createStatement();
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        request.getSession().invalidate();
        e1.printStackTrace();
    }
    try {
        rs = stmt.executeQuery(query);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        request.getSession().invalidate();
        e.printStackTrace();
    }
    %>
    <%
    while(rs.next())
    {

        try {


            ipaddress = rs.getString("ipaddress");
            request.getHeader("VIA");
            $gl = javaQueryBundle.createGeoLocation();
            $gl.MAPTargetByIP(ipaddress, "");
            lat = Double.parseDouble($gl.Latitude);
            lon = Double.parseDouble($gl.Longitude);
        } catch (SQLException e) {
            request.getSession().invalidate();
            e.printStackTrace();
        }
    }
    %>
    <div id="map" style="width: 500px; height: 400px;"></div>

      <script type="text/javascript">
        var locations = [
          ['<%=$gl.City%> ', <%=lat%>, <%=lon%>]
        ];

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 11,
          center: new google.maps.LatLng(<%=lat%>, <%=lon%>),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        var infowindow = new google.maps.InfoWindow();

        var marker;
        var i;

        for (i = 0; i < locations.length; i++) {  
          marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            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>
    </body>
    </html>

地理定位
变量位置=[
[' ', ]
];
var map=new google.maps.map(document.getElementById('map'){
缩放:11,
中心:新google.maps.LatLng(,),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var infowindow=new google.maps.infowindow();
var标记;
var i;
对于(i=0;i
可能是渲染版本?我想知道如何通过查询我知道的数据库,用while循环得到的所有值填充locations数组,但也许您可以在浏览器中发布它的外观