一直报错但是不知道怎么改。。

来源:8-2 驾驶导航

hyperse

2019-08-29 21:36:37

http://img.mukewang.com/climg/5d67d4b2000167d615420636.jpg


new AMap.Lnglat里面的lat应该是Lat吗?

代码如下:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.11&key=9de88a718781910c9a1c81230827d1ce&plugin=AMap.Driving,AMap.Autocomplete"></script>

<title>5-4添加标记练习</title>

<style>

*{

padding: 0;

margin: 0;

}

#container{

position: absolute;

top: 0;

left: 0;

width: 100%;

height: 100%;

}

#panel{

position: fixed;

background: white;

top: 10px;

right: 10px;

width: 280px;

}

#search{

width: 200px;

height: 120px;

position: absolute;

left: 10px;

top: 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>

var map = new AMap.Map('container',{

zoom:11,

center:[116.379391,39.861536],

});

new AMap.Autocomplete({

input:'startNode'

});

new AMap.Autocomplete({

input:'endNode'

});

var num = 0, arr = [];

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

num++;

if(num%2 ==1){

arr = [e.lnglat.R,e.lnglat.P];

}else{

new AMap.Driving({

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);

})

}

});

new AMap.Driving({

map:map,

panel:'panel'

}).search([

{keyword:'北京南站',city:'北京'},

{keyword:'北京西站',city:'北京'}

],function(status,data){

console.log(data);

})

</script>

</body>

</html>


写回答

2回答

好帮手慕夭夭

2019-08-31

你好同学,是因为如下代码拼错,注意单词中第二个L为大写的才对,改过来就行:

http://img.mukewang.com/climg/5d69dd220001676108930123.jpg

祝学习愉快,望采纳。

0
hyperse
h 好的,谢谢老师
h019-08-31
共1条回复

好帮手慕夭夭

2019-08-30

你好同学,老师这次使用你的代码测试正常,没有报错,如下:

http://img.mukewang.com/climg/5d68899b0001d1b610340356.jpg

建议同学再重新测试一下哦。祝学习愉快,望采纳。

0
hyperse
h 就是用鼠标随意点击了一个标记就控制台就会报错说AMap.Lnglat is not a constructor。。
h019-08-30
共1条回复

0 学习 · 6815 问题

查看课程