0

我将 google map api 与 jsp 一起使用,ajax 将更新数据库以显示在 google 地图上。那没起效。地图是空的。看起来谷歌地图没有得到 (lat,lng) 以及如何修复它?

<%@ page language="java" contentType="text/html;charset=utf-8" import="java.io.*"    import="java.util.*" import="java.sql.*"%> 
<% //response.setHeader("refresh","5"); %>  
<html>
<head>


 <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 60% ;}

      #map_canvas { height: 100px;width:100px;  }
    </style>
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
    </script>

  <script type="text/javascript">

function showCustomer(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://localhost:8080/myapp/data.jsp?q="+str,true);
xmlhttp.send();
}

function initialize() 
{
var marker;
        var mapOptions = {
          center: new google.maps.LatLng(lat,lng),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
                }       

    </script>
  </head>
<body bgcolor="FFFFFF">
<body onLoad="initialize()">

<div id="map_canvas" style="width:50%; height:100%"></div>
<div id="txtHint"></div>
Now time is: <%=new java.util.Date()%>
</body></html>

和data.jsp:

<%@ page language="java" contentType="text/html;charset=utf-8" import="java.io.*" import="java.util.*" import="java.sql.*"%> 

<% 

Class.forName("org.postgresql.Driver").newInstance(); 
String url="jdbc:postgresql://localhost/postgres"; 
String user="postgres"; 
String password="123456"; 
Connection conn=DriverManager.getConnection(url,user,password); 
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
String sql="select * from test"; 
ResultSet rs=stmt.executeQuery(sql); 

while(rs.next()){ 
String id = rs.getString("id");
String lat = rs.getString("lat");
String lng = rs.getString("lng");
String time = rs.getString("time");
} 
rs.last();
%> 
<%rs.close();stmt.close();conn.close();%> 
4

0 回答 0