码迷,mamicode.com
首页 > Windows程序 > 详细

调用高德地图web api 规划路线

时间:2020-02-27 09:14:09      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:ref   height   高新   code   cti   lin   需要   万达   输入   

实现地图输出,出发地与目的地路线,效果如下

技术图片

具体代码如下

<!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/

调用高德地图web api 规划路线

标签:ref   height   高新   code   cti   lin   需要   万达   输入   

原文地址:https://www.cnblogs.com/zhuoshengjie/p/12370121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!