当前位置:网站首页>【高德地图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就拿全份,不要从别的什么博文中乱粘贴!
边栏推荐
- Shutter web hardware keyboard monitoring
- What's wrong with this paragraph that doesn't work? (unresolved)
- MySQL advanced part 2: MySQL architecture
- How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
- Leetcode heap correlation
- Usage scenarios of golang context
- Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
- Redis-01.初识Redis
- 2.Oracle-数据文件的添加及管理
猜你喜欢
区间问题 AcWing 906. 区间分组
5.Oracle-表空间
P2575 master fight
LeetCode-54
Real time clock (RTC)
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
求组合数 AcWing 888. 求组合数 IV
Leetcode-6110: number of incremental paths in the grid graph
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
随机推荐
LeetCode 0107. Sequence traversal of binary tree II - another method
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
Leetcode-556: the next larger element III
2022-5-第四周日报
TypeScript 基础讲解
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
Leetcode heap correlation
背包问题 AcWing 9. 分组背包问题
博弈论 AcWing 894. 拆分-Nim游戏
RecyclerView的应用
[learning] database: several cases of index failure
Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
MySQL advanced part 2: storage engine
Leetcode-3: Longest substring without repeated characters
容斥原理 AcWing 890. 能被整除的数
Shutter web hardware keyboard monitoring
Leetcode backtracking method
【LeetCode】Day94-重塑矩阵
Sqlmap tutorial (II) practical skills I
区间问题 AcWing 906. 区间分组