为什么在百度地图中画折线时有的时候不显示?(我想做一个汽车GPS导航,通过折线来画一个正方形的边框,汽车在边框中行驶)

MrHello 发布于 2013/08/13 14:34
阅读 897
收藏 0


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.gps.dao.*"%>
<%@ page import="com.gps.po.*"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">


<title>汽车追踪</title>


<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script
src=" http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">
</script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
body,html,#allmap {
width: 100%;
height: 100%;
overflow: hidden; 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=C539106eb9882e26e4afd5a554baee95"></script>
<script type="text/javascript"
src=" http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
</head>


<body>
<div id="allmap"></div>
<%
String carname = new String(request.getParameter("carname")
.getBytes("ISO-8859-1"), "UTF-8");
String zsx = (String) session.getAttribute("zsx");
String zsy = (String) session.getAttribute("zsy");
String yxx = (String) session.getAttribute("yxx");
String yxy = (String) session.getAttribute("yxy");

if(zsx==null || zsx.equals("")==true){
zsx="120.362066";
zsy="38.52607";

yxx="122.364066";
yxy="36.52407";
}
Double firstx=null;
Double firsty=null;
int count = 0;
Connection con = null;
Statement st = null;
ResultSet rs = null;
ResultSet rs2=null;
Class.forName("com.mysql.jdbc.Driver");
/*url后面加的?useUnicode=true&characterEncoding=gbk,是为了处理向数据库中添加数据时出现乱码的问题。*/
String url = "jdbc:mysql://localhost:3306/cars?useUnicode=true&characterEncoding=gbk";
con = DriverManager.getConnection(url, "root", "root");
st = con.createStatement();


String query = "select * from carsinfo  where carname='" + carname
+ "'";
rs = st.executeQuery(query);
if (rs.next() == false) {
%>
<script type="text/javascript">
  alert("无此汽车!点击返回!");
  history.go(-1);
 
 </script>
<%
//  response.sendRedirect("http://localhost:8080/gps/index.jsp");

} else {
String sql="select * from gps where carname='"+carname+"'";
rs2=st.executeQuery(sql);
if(rs2.next()==true){
firstx=rs2.getDouble("x");
firsty=rs2.getDouble("y");
}else{
firstx=121.363066;
firsty=37.52507;
}
//  
}
%>
<input type="hidden" id="zsx" value="<%=zsx%>" />
<input type="hidden" id="zsy" value="<%=zsy%>" />
<input type="hidden" id="yxx" value="<%=yxx%>" />
<input type="hidden" id="yxy" value="<%=yxy%>" />

<input type="hidden" id="carname" value="<%=carname%>" />

<input type="hidden" id="firstx" value="<%=firstx %>"/>
<input type="hidden" id="firsty" value="<%=firsty %>"/>
</body>
</html>
<script type="text/javascript">

// var marker1;
var marker=new Array();
var map;
var points = new Array();
var i=0;
var zsx,zsy,yxx,yxy;
var carname;
var firstx,firsty;
zsx=$("#zsx").val();
zsy=$("#zsy").val();
yxx=$("#yxx").val();
yxy=$("#yxy").val();
carname=$("#carname").val();


firstx=$("#firstx").val();
firsty=$("#firsty").val();
map=new  BMap.Map("allmap");map.enableScrollWheelZoom();
var gpsPoint=new BMap.Point(firstx, firsty),

one=new BMap.Point(zsx, zsy),
two=new BMap.Point(yxx, zsy),
three=new BMap.Point(yxx, yxy),
four=new BMap.Point(zsx, yxy),
five=new BMap.Point(zsx, zsy);
// alert(gpsPoint);
var a;
translateCallbackone = function (point00){
// points[0]=point00;
a=parseFloat(point00.lng);

points[0]=new BMap.Point(a,parseFloat(point00.lat));
// alert(points[0].lng);
// alert(points[0].lat);

}

translateCallbacktwo = function (point11){
// points[1]=point11;
points[1]=new BMap.Point(parseFloat(point11.lng),parseFloat(point11.lat));
}


translateCallbackthree = function (point22){
// points[2]=point22;
points[2]=new BMap.Point(parseFloat(point22.lng),parseFloat(point22.lat));
}


translateCallbackfour = function (point33){
// points[3]=point33;
points[3]=new BMap.Point(parseFloat(point33.lng),parseFloat(point33.lat));
}


translateCallbackfive = function (point44){
// points[4]=point44;
points[4]=new BMap.Point(parseFloat(point44.lng),parseFloat(point44.lat));
// alert("123");
// alert(points[0].lng);
// alert(points[2].lng);
var curve = new BMap.Polyline(points, {strokeColor:"blue", strokeWeight:3, strokeOpacity:0.5}); //创建弧线对象
map.addOverlay(curve); //添加到地图中
curve.enableEditing();
}
// alert(a);
BMap.Convertor.translate(one,0,translateCallbackone);
BMap.Convertor.translate(two,0,translateCallbacktwo);
BMap.Convertor.translate(three,0,translateCallbackthree);
BMap.Convertor.translate(four,0,translateCallbackfour);
BMap.Convertor.translate(five,0,translateCallbackfive);
// a=1.2;
// alert(a);










// var temp;
translateCallback2 = function (point2){


map.panTo(point2);

// temp=new BMap.Point(point2);
// alert(temp);
// map.panTo(temp);
map.removeOverlay(marker[i-1]);

marker[i] = new BMap.Marker(point2);
map.addOverlay(marker[i]);
// point2.toString();
// alert(point2);
}
translateCallback = function (point){
map.centerAndZoom(point, 19);
marker[1] = new BMap.Marker(point);
map.addOverlay(marker[1]);
}
BMap.Convertor.translate(gpsPoint,0,translateCallback);
// map.centerAndZoom(new BMap.Point(121.363066, 37.52507), 19);
// marker[1] = new BMap.Marker(new BMap.Point(121.363066, 37.52507));
// map.addOverlay(marker[1]);
var xx,yy;
// alert(carname);
var count=1;
function dfs(){

$.post("getX.jsp",{carname:carname},function(data,status){
xx=data;
xx=$.trim(data); 
// alert(xx);
});
$.post("getY.jsp",{carname:carname},function(data,status){
yy=data;
yy=$.trim(data); 
// alert(yy);
});




i++;
if(i==1){


}

else{
<%// out.print(x);%>
// map=new  BMap.Map("allmap");
//
// alert(i);

var nx,ny;
nx=parseFloat(xx);
ny=parseFloat(yy);
// alert(nx);
// map.centerAndZoom(new BMap.Point(121.363066, 37.52507), 19);
// map.panTo(new BMap.Point(xx, yy));
var gpsPoint2=new BMap.Point(nx,ny);
BMap.Convertor.translate(gpsPoint2,0,translateCallback2);
if((nx>yxx || nx<zsx || ny>zsy || ny<yxy) && count==1){
alert(carname+"不在规定范围内行驶");
count++;
// alert(count);
}
// map.panTo(new BMap.Point(nx,ny));
// map.removeOverlay(marker[i-1]);

// marker[i] = new BMap.Marker(new BMap.Point(nx,ny));
// map.addOverlay(marker[i]);
}
setTimeout(dfs,2000);
}
dfs();
</script>

加载中
返回顶部
顶部