当前位置:网站首页>【高德地图POI踩坑】AMap.PlaceSearch无法使用
【高德地图POI踩坑】AMap.PlaceSearch无法使用
2022-07-05 06:23:00 【Heerey525】
情况
近期有需要用到高德地图的搜索功能
步骤
申请key
在高德地图的开放平台注册账号并申请Key,得到key和安全密钥
找到案例
在文档中到功能 输入提示与POI搜索
进入demo
选择我需要的功能 输入提示后查询,发现符合我的预期。
本地运行demo
直接将上一步骤的demo拷贝,在本地运行。
还需要注意一点是后期使用需要将安全密钥也带上。
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode:'你的安全密钥',
}
</script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你申请的key"></script>
搜索无提示
直接拷贝的代码,添加上key和安全密钥,搜索竟然不能提示地址。
<!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>
<link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
</head>
<body>
<div id="container"></div>
<div id="myPageTop">
<table>
<tr>
<td>
<label>请输入关键字:</label>
</td>
</tr>
<tr>
<td>
<input id="tipinput"/>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode:'你的安全密钥',
}
</script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你申请的key"></script>
<script type="text/javascript">
//地图加载
var map = new AMap.Map("container", {
resizeEnable: true
});
//输入提示
var autoOptions = {
input: "tipinput"
};
AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){
var auto = new AMap.AutoComplete(autoOptions);
var placeSearch = new AMap.PlaceSearch({
map: map
}); //构造地点查询类
auto.on("select", select);//注册监听,当选中某条记录时会触发
function select(e) {
placeSearch.setCity(e.poi.adcode);
placeSearch.search(e.poi.name); //关键字查询查询
}
});
</script>
</body>
</html>
百度搜索无果
百度搜索一圈
有说将插件使用 由 AMap.plugin
变更为 AMap.service
,不起作用
有说将插件使用 由 AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){})
变更为 同步方式 <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你申请的key&plugin=AMap.PlaceSearch,AMap.AutoComplete"></script>
,不起作用
还有其他一些文章也不管用
还得从官方文档找
?,这句话在我刚开始直接忽略,难道是版本问题,回头看我代码中的https://webapi.amap.com/maps?v=1.4.15
,竟然是1.4.15 ???,然后我将代码中AutoComplete
改成Autocomplete
,哇哦,成功!!!
反思
以后拿官方的demo就拿全份,不要从别的什么博文中乱粘贴!
边栏推荐
- 博弈论 AcWing 894. 拆分-Nim游戏
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Leetcode-3: Longest substring without repeated characters
- ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
- Daily question 1189 Maximum number of "balloons"
- 安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
- Quickly use Amazon memorydb and build your own redis memory database
- Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
- [rust notes] 16 input and output (Part 1)
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
猜你喜欢
博弈论 AcWing 891. Nim游戏
Is it impossible for lamda to wake up?
什么是套接字?Socket基本介绍
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
MySQL advanced part 2: optimizing SQL steps
4. 对象映射 - Mapping.Mapster
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
随机推荐
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
RecyclerView的应用
Leetcode dynamic programming
4.Oracle-重做日志文件管理
There are three kinds of SQL connections: internal connection, external connection and cross connection
2048项目实现
中国剩余定理 AcWing 204. 表达整数的奇怪方式
[rust notes] 16 input and output (Part 1)
Leetcode stack related
MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
MySQL advanced part 1: index
MySQL advanced part 1: stored procedures and functions
[rust notes] 17 concurrent (Part 2)
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
International Open Source firmware Foundation (osff) organization
Real time clock (RTC)
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
Leetcode-3: Longest substring without repeated characters
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
Is it impossible for lamda to wake up?