html5 计算步行数,高德地图API之步行路线

步行路线

引入插件 amap.walking

map

*{margin:0;padding:0;list-style: none;}

#container {width:100%; height: 100%;top:0;left:0;position: absolute; }

#panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;}

var map=new amap.map("container",{

zoom:11

});

//使用插件

new amap.walking({

map:map,

panel:"panel"

}).search([

{keyword:"宁波大学",city:"宁波"},

{keyword:"汽车东站",city:"宁波"}

],function(status,data){

console.log(data);

});

a3ea6e9b6418a2017d62d151bca10f6b.png

输入起点和终点,点击按钮规划路线

map

*{margin:0;padding:0;list-style: none;}

#container {width:100%; height: 100%;top:0;left:0;position: absolute; }

#panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;}

#search{position: absolute;width:200px;height:100px;top:10px;left:10px;background-color: #fff;}

var map=new amap.map("container",{

zoom:11

});

// 给起点和终点添加自动补全功能

new amap.autocomplete({

input:"node1"

})

new amap.autocomplete({

input:"node2"

})

btn.οnclick=function(){

//使用插件

new amap.walking({

map:map,

panel:"panel"

}).search([

{keyword:node1.value,city:"宁波"},

{keyword:node2.value,city:"宁波"}

],function(status,data){

console.log(data);

});

}

456d48334afadf78c4eee51b3321c4ee.png

通过经纬度来进行导航

实现鼠标点击两个地址,自动进行导航

map

*{margin:0;padding:0;list-style: none;}

#container {width:100%; height: 100%;top:0;left:0;position: absolute; }

#panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;}

#search{position: absolute;width:200px;height:100px;top:10px;left:10px;background-color: #fff;}

var map=new amap.map("container",{

zoom:11

});

var i=0,arr=[];

map.on("click",function(e){

i++;

console.log(i);

if(i%2==1){

arr=[e.lnglat.r,e.lnglat.q];

}else{

//使用插件

new amap.walking({

map:map,

panel:"panel"

}).search(new amap.lnglat(arr[0],arr[1]),new amap.lnglat(e.lnglat.r,e.lnglat.q),function(status,data){

console.log(data);

});

}

})

a1375f81e26bb0625accf1ef97087314.png

常规用法

map

*{margin:0;padding:0;list-style: none;}

#container {width:100%; height: 100%;top:0;left:0;position: absolute; }

#panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;}

#search{position: absolute;width:200px;height:100px;top:10px;left:10px;background-color: #fff;}

var map=new amap.map("container",{

zoom:11

});

console.log(map.getcenter().tostring());//121.549792,29.868388

new amap.walking({

map:map,

panel:"panel"

}).search([121.549792,29.868388],[121.549792,29.468388],function(status,data){

console.log(data);

});

e730556cad856ff24b2fbb13c43f442c.png

注意:如果是大于两个定位点,不能直接添加第三个,会报错

search中传的数组只能传2个

map

*{margin:0;padding:0;list-style: none;}

#container {width:100%; height: 100%;top:0;left:0;position: absolute; }

#panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;}

#search{position: absolute;width:200px;height:100px;top:10px;left:10px;background-color: #fff;}

var map=new amap.map("container",{

zoom:11

});

console.log(map.getcenter().tostring());//121.549792,29.868388

new amap.walking({

map:map,

panel:"panel"

}).search([121.549792,29.868388],[121.549792,29.468388],[121.549792,29.368388],function(status,data){

console.log(data);

});

5d7a600844cde3df988665ba7ea5df48.png

正确的多点规划做法:(在每个定位点外面用再用数组括号包起来)

map

*{margin:0;padding:0;list-style: none;}

#container {width:100%; height: 100%;top:0;left:0;position: absolute; }

#panel{position: fixed;width:280px;top:10px;right:10px;background-color: #fff;}

#search{position: absolute;width:200px;height:100px;top:10px;left:10px;background-color: #fff;}

var map=new amap.map("container",{

zoom:11

});

console.log(map.getcenter().tostring());//121.549792,29.868388

new amap.walking({

map:map,

panel:"panel"

}).search([[121.549792,29.868388],[121.549792,30.468388],[121.549792,31.368388]],function(status,data){

//console.log(data);

});

现在无效了,我估计因为版本迭代被取消了吧!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值