当前位置:网站首页>【高德地图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就拿全份,不要从别的什么博文中乱粘贴!
边栏推荐
- 5. Oracle tablespace
- Quickly use Amazon memorydb and build your own redis memory database
- What is socket? Basic introduction to socket
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- How to generate an image from text on fly at runtime
- Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
- 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
- Navicat连接Oracle数据库报错ORA-28547或ORA-03135
- C Primer Plus Chapter 15 (bit operation)
- 3.Oracle-控制文件的管理
猜你喜欢
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
Open source storage is so popular, why do we insist on self-development?
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
栈 AcWing 3302. 表达式求值
博弈论 AcWing 892. 台阶-Nim游戏
博弈论 AcWing 893. 集合-Nim游戏
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
随机推荐
How to generate an image from text on fly at runtime
TypeScript 基础讲解
[rust notes] 14 set (Part 1)
Chart. JS - Format Y axis - chart js - Formatting Y axis
C Primer Plus Chapter 15 (bit operation)
Leetcode-6111: spiral matrix IV
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
Basic explanation of typescript
Sqlmap tutorial (1)
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
MySQL advanced part 1: index
Currently clicked button and current mouse coordinates in QT judgment interface
Quickly use Amazon memorydb and build your own redis memory database
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
C - XOR to all (binary topic)
[moviepy] unable to find a solution for exe
Leetcode-6109: number of people who know secrets
博弈论 AcWing 893. 集合-Nim游戏
背包问题 AcWing 9. 分组背包问题
Dataframe (1): introduction and creation of dataframe