<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> multi-positioning points between the moving </title>
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=2.0& own id" ></script>
<body>
<div>
<input type= ' button ' value= ' Start ' onclick= ' run (); ' style= ' z-index:999; '/>
<div style= "width:1320px;height:640px;border:1px solid Gray" id= "container" >
</div>
</div>
</body>
<script type= "Text/javascript" >
var q={"state": "0", "devices": [{"pt": "2016-12-21 12:00:29", "lat": "22.68545", "LNG": "114.06649", "s": "28.00", "C": " 284 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:00:29 "," lat ":" 22.68545 "," LNG ":" 114.06649 "," s ":" 28.00 "," C ":" 284 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:00:49 "," lat ":" 22.68587 "," LNG ":" 114.06444 "," s ":" 52.00 "," C ":" 278 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:00:49 "," lat ":" 22.68587 "," LNG ":" 114.06444 "," S ":" 52.00 "," C ":" 278 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:01:09 "," lat ":" 22.68621 "," LNG ":" 114.06131 "," s ":" 59.00 "," C ":" 276 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:01:29 "," lat ":" 22.68657 "," LNG ":" 114.05812 "," s ":" 62.00 "," C ":" 276 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:01:49 "," lat ":" 22.68691 "," LNG ":" 114.05495 "," s ":" 57.00 "," C ":" 275 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:02:09 "," Lat ":" 22.68715 "," LNG ":" 114.05189 "," s ":" 55.00 "," C ":" + "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:02:29 "," lat ":" 22.68717 "," lNg ":" 114.04851 "," s ":" 65.00 "," C ":" 268 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:02:29 "," lat ":" 22.68717 "," LNG ":" 114.04851 "," s ":" 65.00 "," C ":" 268 "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:02:49 "," lat ":" 22.68714 "," LNG ":" 114.04504 "," s ":" 62.00 "," C ":" + "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "},{" PT ":" 2016-12-21 12:02:49 "," Lat ":" 22.68714 "," LNG ":" 114.04504 "," s ":" 62.00 "," C ":" + "," Stop ":" 0 "," STM ":" 0 "," G ":" 1 "}]}
var devices= q.devices;
var len=devices.length;
var map = new Bmap.map ("container");
Map.centerandzoom (New Bmap.point (Devices[0].lng,devices[0].lat), 15);
var myP1 = new Bmap.point (Devices[0].lng,devices[0].lat); Starting point
var myP2 = new Bmap.point (Devices[len-1].lng,devices[len-1].lat); End
var myiconmove = new Bmap.icon ("Http://dev.baidu.com/wiki/static/map/API/examples/images/Mario.png", New Bmap.size ( 32, 70), {//Cart picture
Offset:new bmap.size (0,-5),//equivalent to CSS Sprites
Imageoffset:new bmap.size (0, 0)//image offset. In order to align the coordinates at the bottom center of the picture.
});
var driving2 = new Bmap.drivingroute (map, {renderoptions:{map:map, autoviewport:false}}); Driving example
Driving2.search (myP1, myP2); Show a bus line
Add Flag
Add a final flag
var point = new Bmap.point (Devices[0].lng,devices[0].lat);
Add Flag
Add a final flag
var Myicon = new Bmap.icon ("Http://api.map.baidu.com/img/dest_markers.png", new Bmap.size (+), {offset:new BMap. Size (Ten), Imageoffset:new bmap.size (0, 0)});
var myIcon2 = new Bmap.icon ("Http://api.map.baidu.com/img/dest_markers.png", new Bmap.size (+), {offset:new BMap . Size ( -150, -205), Imageoffset:new bmap.size (0,-34)});
var point2 = new Bmap.point (Devices[len-1].lng,devices[len-1].lat);
var marker = new Bmap.marker (point, {icon:myicon}); Create a callout
var marker2 = new Bmap.marker (Point2, {icon:myicon2}); Create a callout
Map.addoverlay (marker); Add a callout to a map
Map.addoverlay (MARKER2);
Marker.setanimation (Bmap_animation_drop); Bouncing animations
Marker2.setanimation (Bmap_animation_drop); Bouncing animations
var points = []; Add massive point data
for (Var i=0;i<len;i++) {
var p = new Bmap.point (DEVICES[I].LNG, Devices[i].lat);
P.data = "Http://blog.csdn.net/wang_song_yan";
Points.push (P);
}
var polyline = new Bmap.polyline (points, {strokecolor: "Blue", Strokeweight:3, strokeopacity:0.5});
Map.addoverlay (polyline);
function Run () {
var driving = new Bmap.drivingroute (map); Driving example
Driving.search (Point, Point2);
Driving.setsearchcompletecallback (function () {
Debugger
var pts = Driving.getresults (). Getplan (0). Getroute (0). GetPath (); Get an array of points by driving an instance
PTS =points;
var paths = Pts.length; Get a few points
Alert (pts.tostring ());
var carmk = new Bmap.marker (pts[0]);
Map.addoverlay (CARMK);
i=0;
function Resetmkpoint (i) {
Carmk.setposition (Pts[i]);
if (I < paths) {
SetTimeout (function () {
i++;
Resetmkpoint (i);
},500);
}else{map.removeoverlay (CARMK);}
}
SetTimeout (function () {
Resetmkpoint (0);
},800)
});
}
</script>
Baidu Map Multi-location move between points