首页 > 代码库 > baidu地图:实现多点连线渲染
baidu地图:实现多点连线渲染
<script type="text/javascript">var points = [{"Lng":120.17787645967861,"Lat":30.251826748722667},{"Lng":120.17786646842835,"Lat":30.251826580357911}]; </script><!DOCTYPE html><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=E06eb9d756d0eafc722effb355657b4c"></script> <title>GPS转百度</title></head><body> <div id="allmap"></div></body></html><script type="text/javascript"> // 百度地图API功能 //GPS坐标 var x = 120.17730456267518; var y = 30.250142055599344; var ggPoint = new BMap.Point(x,y); //地图初始化 var bm = new BMap.Map("allmap"); bm.centerAndZoom(ggPoint, 25); //bm.addControl(new BMap.NavigationControl()); bm.addControl(new BMap.MapTypeControl()); //添加地图类型控件 bm.setCurrentCity("杭州"); // 设置地图显示的城市 此项是必须设置的 bm.enableScrollWheelZoom(true); //开启鼠标滚轮缩放 var pointsGps=[]; for(var i=0;i<points.length;i++){ pointsGps.push(new BMap.Point(points[i].Lng, points[i].Lat)); } var polyline = new BMap.Polyline(pointsGps, {strokeColor:"red", strokeWeight:2, strokeOpacity:0.5}); //创建折线 bm.addOverlay(polyline); //增加折线 for(var i=0;i<pointsGps.length;i++){ //添加gps marker和label var markergg = new BMap.Marker(pointsGps[i]); bm.addOverlay(markergg); //添加GPS marker var labelgg = new BMap.Label(i+1,{offset:new BMap.Size(20,-10)}); markergg.setLabel(labelgg); //添加GPS label }</script>
baidu地图:实现多点连线渲染
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。