<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>
原文:http://www.cnblogs.com/yy3b2007com/p/7163588.html