cuogeyibi 2013-06-01 04:09 采纳率: 0%
浏览 6821

JSP从数据库MySQL取出经纬度数据,怎么能够在百度地图上描绘出轨迹

<%@ page contentType="text/html; charset=utf-8" %>

<%@ page language="java" %>

<%@ page import="com.mysql.jdbc.Driver" %>

<%@ page import="java.sql.*" %>

<% 
String driverName="com.mysql.jdbc.Driver";//驱动程序名
String userName="root";//数据库用户名
String userPasswd="qwe";//密码
String dbName="test";//数据库名
String tableName="location";//表名
//联结字符串
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="SELECT * FROM "+tableName;
ResultSet rs = statement.executeQuery(sql);
int size = rs.getRow();//数据行数
ResultSetMetaData rmeta = rs.getMetaData();//获得数据结果集合
int numColumns=rmeta.getColumnCount();//确定数据集的列数,亦字段数
//输出每一个数据值
out.print(size+"    ");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString(1)+" ");//编号
out.print("|");
Double point1=rs.getDouble(4);
Double point2=rs.getDouble(3);
out.print(point1+" ");//输出经度
out.print(point2+" ");//输出纬度
out.print("<br>");
}
%>

<!DOCTYPE html>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=2a8432fa52e468d4644b16afa735618e"></script>
<title>折线</title>

<body>


<div id="allmap"></div>
<script type="text/javascript">

var map = new BMap.Map("allmap");
var point = new BMap.Point(113.001,28.23540605);
var p=document.from1.myhidden.value;
map.centerAndZoom(point, 13);

var polyline = new BMap.Polyline([
  new BMap.Point(113.0051,28.2334),
  new BMap.Point(113.0031,28.2322),
  new BMap.Point(113.0041,28.23241)
], {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5});//这里的坐标需要从数据库获取!! 卡在这里了
map.addOverlay(polyline);
</script>
</body>
</html>
  • 写回答

2条回答

  • xie879092 2015-09-11 02:02
    关注

    这个问题解决了吗?我也想问这个问题!

    评论

报告相同问题?

悬赏问题

  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)