高德地图——骑行导航

高德地图——骑行导航

插件:plugin=AMap.Riding //中间不能有途径
在这里插入图片描述
1.骑行路线——使用keyword

new AMap.Riding({
    map:map,
    panel:'panel'
}).search([
    {keyword:startNode.value,city:'北京'}, //起点
    {keyword:endNode.value,city:'北京'} //终点 
    //不能中间有途径
],function(status,data){
    console.log(data);
})

```javascript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.15&key=34614f775ec9455cf2f9a5c7bb6acfa0&plugin=AMap.Riding,AMap.Autocomplete"></script>
<style type="text/css">
        *{margin: 0;padding: 0;list-style: none;}
    	#container{width: 100%;height: 100%;position: absolute;left: 0;top: 0;}
        #panel{position: fixed;background: white;top: 10px;right: 10px;width: 280px;}
        #search{width: 200px;height: 100px;position: absolute;left: 10px;right: 10px;background: white;}
</style>
    </head>
<body>
    <div id="container"></div> 
    <div id="panel"></div>
    <div id="search">
        起点:<input type="text" name="" id="startNode"><br>
        终点:<input type="text" name="" id="endNode"><br>
        <button id="btn">开始导航</button>
    </div>
    <script type="text/javascript">
		var map = new AMap.Map('container',{
            zoom:11,
            center:[116.379391,39.861536],
        });

        new AMap.Autocomplete({
            input:'startNode'
        });
        new AMap.Autocomplete({
            input:'endNode'
        });
        btn.onclick = function(){
            new AMap.Riding({
                map:map,
                panel:'panel'
            }).search([
                {keyword:startNode.value,city:'北京'},
                {keyword:endNode.value,city:'北京'}
            ],function(status,data){
                console.log(data);
            })
        }
	</script> 
</body>
</html>

2.点击任意两点的坐标

new AMap.Riding({
    map:map,
    panel:'panel'
    }).search(new AMap.LngLat(startX,startY),new AMap.LngLat(endX,endY),function(status,data){
        console.log(data);
})
<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title></title> 
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.11&key=e22196035aaa10db3b0b6eb1ab64619e&plugin=AMap.Riding,AMap.Autocomplete"></script> 
    <style type="text/css">
    	*{margin: 0;padding: 0;list-style: none;}
    	#container{width: 100%;height: 100%;position: absolute;left: 0;top: 0;}
        
        #panel{
            position: fixed;
            background: white;
            top: 10px;
            right: 10px;
            width: 280px;
        }
        #search{width: 200px;height: 100px;position: absolute;left: 10px;top: 10px;background: white;}

    </style>
</head>
<body>
	<div id="container"></div> 
    <div id='panel'></div>
    <div id='search'>
        起点:<input type="" name="" id='startNode'><br>
        终点:<input type="" name="" id='endNode'><br>
        <button id='btn'>开始导航</button>
    </div>

    
	<script type="text/javascript">
        var map = new AMap.Map('container',{
            zoom:11,
            center:[116.379391,39.861536],
        });

/*
        new AMap.Riding({
            map:map,
            panel:'panel'
            }).search([[116.379391,39.861536],[116.979391,39.161536],[116.979391,39.161536],[116.979391,39.161536]],function(status,data){
                console.log(data);
        })
*/
/*
        new AMap.Autocomplete({
            input:'startNode'
        });

        new AMap.Autocomplete({
            input:'endNode'
        });
*/
        var num = 0, arr = [];

        map.on('click',function(e){
        //    console.log(e.lnglat)
            num++;
            if(num%2 == 1){
                arr = [e.lnglat.R,e.lnglat.P];
            }
            else{
                new AMap.Riding({
                    map:map,
                    panel:'panel'
                    }).search(new AMap.LngLat(arr[0],arr[1]),new AMap.LngLat(e.lnglat.R,e.lnglat.P),function(status,data){
                        console.log(data);
                })
                //arr = [];
            }
        });
/*
        btn.onclick = function(){
            new AMap.Driving({
            map:map,
            panel:'panel'
            }).search([
                {keyword:startNode.value,city:'北京'},
                {keyword:endNode.value,city:'北京'}
            ],function(status,data){
                console.log(data);
            })
        };
*/      
	</script>
</body>
</html>
发布了40 篇原创文章 · 获赞 0 · 访问量 756

猜你喜欢

转载自blog.csdn.net/qq_34634181/article/details/103069670
今日推荐