我是靠谱客的博主 害羞铃铛,这篇文章主要介绍开发百度地图路径移动,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";} </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你自己的AK"></script> <title>百度地图利用DrivingRoute做轨迹回放</title> </head> <body> <div id="allmap"></div> </body> </html> <script type="text/javascript"> // 百度地图API功能       var map = new BMap.Map("allmap");  // 创建Map实例 map.centerAndZoom("哈尔滨",15);      // 初始化地图,用城市名设置地图中心点 map.setMapStyle({ //可以自己定义地图底图 http://developer.baidu.com/map/custom/ styleJson:[           {                     "featureType": "water",                     "elementType": "all",                     "stylers": {                               "color": "#72b8fe"                     }           },           {                     "featureType": "road",                     "elementType": "geometry.fill",                     "stylers": {                               "color": "#ffffff"                     }           },           {                     "featureType": "road",                     "elementType": "geometry.stroke",                     "stylers": {                               "color": "#bababa"                     }           },           {                     "featureType": "road",                     "elementType": "labels.text.fill",                     "stylers": {                               "color": "#767676"                     }           },           {                     "featureType": "road",                     "elementType": "labels.text.stroke",                     "stylers": {                               "color": "#ffffff"                     }           },           {                     "featureType": "land",                     "elementType": "all",                     "stylers": {                               "color": "#b8cb93"                     }           } ]     });     map.addControl(new BMap.NavigationControl());             map.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT}));     map.enableScrollWheelZoom(true); var pts = [     new BMap.Point(126.618398,45.721217),     new BMap.Point(126.62081,45.713008),     new BMap.Point(126.654694,45.732086),     new BMap.Point(126.675481,45.738471)  ];    var polyline ;    var options = { onSearchComplete: function(results){ if (driving.getStatus() == BMAP_STATUS_SUCCESS){ // 获取第一条方案 var plan = results.getPlan(0); // 获取方案的驾车线路 var route = plan.getRoute(0); //返回路线的地理坐标点数组。(自 1.2 新增) var points = route.getPath(); polyline = new BMap.Polyline(points); //alert(points.length); map.addOverlay(polyline);          //增加折线 } } //, //renderOptions:{map: map, autoViewport: true} };    var driving = new BMap.DrivingRoute(map, options);             i=0; function playLine(i){ if(i==0){//第一个点 直接添加 var marker = new BMap.Marker(pts[i]);  // 创建标注 map.addOverlay(marker);  marker.setLabel(new BMap.Label("我是第"+(i+1)+"个点",{offset:new BMap.Size(20,-10)})); map.panTo(pts[i]); i++; setTimeout(function(){ playLine(i); },2000) }else{//获取PolyLine并添加 添加点 if(i<=pts.length){ driving.search(pts[i-1], pts[i]);  map.addOverlay(polyline); var marker = new BMap.Marker(pts[i]);  // 创建标注     map.addOverlay(marker); marker.setLabel(new BMap.Label("我是第"+(i+1)+"个点",{offset:new BMap.Size(20,-10)})); map.panTo(pts[i]); i++; setTimeout(function(){ playLine(i); },2000) } } }     playLine(i); </script>

最后

以上就是害羞铃铛最近收集整理的关于开发百度地图路径移动的全部内容,更多相关开发百度地图路径移动内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部