調用高德地圖web api 規划路線


實現地圖輸出,出發地與目的地路線,效果如下

具體代碼如下

<!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>
    <style type="text/css">
    html,
    body,
    #container {
      width: 100%;
      height: 100%;
    }
    </style>
    <style type="text/css">
        #panel {
            position: fixed;
            background-color: white;
            max-height: 90%;
            overflow-y: auto;
            top: 10px;
            right: 10px;
            width: 280px;
        }
        #panel .amap-call {
            background-color: #009cf9;
            border-top-left-radius: 4px;
   	        border-top-right-radius: 4px;
        }
        #panel .amap-lib-driving {
	        border-bottom-left-radius: 4px;
   	        border-bottom-right-radius: 4px;
            overflow: hidden;
        }
    </style>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=請輸入您的key&plugin=AMap.Driving"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
</head>
<body>
<div id="container"></div>
<div id="panel"></div>
<script type="text/javascript">
    //基本地圖加載
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [116.397428, 39.90923],//地圖中心點
        zoom: 13 //地圖顯示的縮放級別
    });
    //構造路線導航類
    var driving = new AMap.Driving({
        map: map,
        panel: "panel"
    }); 
    // 根據起終點名稱規划駕車導航路線
    driving.search([
        {keyword: '濟南火車站',city:'濟南'},
        {keyword: '高新區萬達廣場',city:'濟南'}
    ], function(status, result) {
        // result 即是對應的駕車導航信息,相關數據結構文檔請參考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
        if (status === 'complete') {
            log.success('繪制駕車路線完成')
        } else {
            log.error('獲取駕車數據失敗:' + result)
        }
    });
</script>
</body>
</html>

  使用高德api,需要注冊高德平台,獲取key。https://lbs.amap.com/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM