高德地图——公交规划

高德地图——公交规划

插件:plugin=AMap.Transfer
1.使用关键字——只支持数组的前两个内容,第三个无效

<!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.Transfer,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.Transfer({
                map:map,
                panel:'panel'
            }).search([
                {keyword:startNode.value,city:'北京'},
                {keyword:endNode.value,city:'北京'}
            ],function(status,data){
                console.log(data);
            })
        }
	</script>
</body>
</html>

2.使用坐标——city 一定要加上 城市 如果咱们导航的地址比较偏僻 也不可以

<!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.Transfer,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],
        });
        var num =0,arr=[];
        map.on('click',function(e){
            num++;
            if(num%2==1){
                arr=[e.lnglat.Q,e.lnglat.P];
            }else{
                new AMap.Transfer({
                    map:map,
                    panel:'panel',
                    city:'北京'
                }).search(new AMap.LngLat(arr[0],arr[1]),new AMap.LngLat(e.lnglat.Q,e.lnglat.P),
                function(status,data){
                    console.log(data);
                })
            }
        });
	</script>  
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值