标签:width html ast device ref 1.0 time ons style
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <title>路线规划</title> <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main.css"/> <script type="text/javascript" src="js/jquery-1.10.2.js" ></script> <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.0&key=5bffad5c5d7992363d1eb9518dcc3e9d"></script> </head> <body> <div id="mapContainer"></div> <div id="panel"></div> <script type="text/javascript"> window.onload=function(){ getRoad("Driving","最短距离模式",[103.912339,30.755537],[103.920859,30.757879]); }; //规划不同的导航路线 function getRoad(type,way,lnglat1,lnglat2){ var map = new AMap.Map("mapContainer", { resizeEnable: true }); //路线规划策略 var policy=function(){ switch(type){ case "Driving": switch(way){ case "考虑实时路况" : return AMap.DrivingPolicy.REAL_TRAFFIC;break; //考虑实时路况 case "最经济模式" : return AMap.DrivingPolicy.LEAST_FEE; break; //最经济模式 case "最短距离模式" : return AMap.DrivingPolicy.LEAST_DISTANCE; break; //最短距离模式 default : return AMap.DrivingPolicy.LEAST_TIME;break; //最快捷模式 }; break; case "Transfer": switch(way){ case "最经济模式" : return AMap.TransferPolicy.LEAST_FEE; break; //最经济模式 case "最少换乘模式" : return AMap.TransferPolicy.LEAST_TRANSFER; break; //最少换乘模式 case "最少步行模式" : return AMap.TransferPolicy.LEAST_WALK; break; //最少步行模式 case "最舒适模式" : return AMap.TransferPolicy.MOST_COMFORT; break; //最舒适模式 case "不乘地铁模式" : return AMap.TransferPolicy.NO_SUBWAY; break; //不乘地铁模式 default : return AMap.TransferPolicy.LEAST_TIME ;break; //最快捷模式 }; break; default : break; } }; AMap.service(["AMap."+type], function() { var transOptions = { map: map, panel:panel, city: "成都市", policy: policy() }; var trans; switch(type){ case "Driving": trans = new AMap.Driving(transOptions);break; case "Walking": trans = new AMap.Walking(transOptions);break; case "Riding": trans = new AMap.Riding(transOptions);break; default: trans = new AMap.Transfer(transOptions);break; } //根据起、终点坐标查询公交换乘路线 trans.search(lnglat1, lnglat2, function(status, result){}); }); } </script> </body> </html>
高德js API根据出行方式和出现策略由起始点经纬度实现路线规划
标签:width html ast device ref 1.0 time ons style
原文地址:http://www.cnblogs.com/fuxuyang/p/7673185.html