当前位置:网站首页>【高德地图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就拿全份,不要从别的什么博文中乱粘贴!
边栏推荐
- Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
- 2021apmcm post game Summary - edge detection
- Leetcode-1200: minimum absolute difference
- Leetcode heap correlation
- Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
- 5.Oracle-表空间
- Leetcode-31: next spread
- How to understand the definition of sequence limit?
- C Primer Plus Chapter 15 (bit operation)
- 1.14 - assembly line
猜你喜欢

Operator priority, one catch, no doubt

How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling

快速使用Amazon MemoryDB并构建你专属的Redis内存数据库

Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne

论文阅读报告

Bit of MySQL_ OR、BIT_ Count function

博弈论 AcWing 893. 集合-Nim游戏

Error ora-28547 or ora-03135 when Navicat connects to Oracle Database

MySQL advanced part 2: SQL optimization

MySQL advanced part 2: storage engine
随机推荐
Single chip computer engineering experience - layered idea
博弈论 AcWing 891. Nim游戏
Leetcode-6109: number of people who know secrets
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
4. 对象映射 - Mapping.Mapster
Presentation of attribute value of an item
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
7.Oracle-表结构
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
TypeScript 基础讲解
[rust notes] 16 input and output (Part 1)
C Primer Plus Chapter 15 (bit operation)
栈 AcWing 3302. 表达式求值
[wustctf2020] plain_ WP
Sqlmap tutorial (II) practical skills I
Leetcode-3: Longest substring without repeated characters
Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
2022-5-第四周日报
Golang uses context gracefully
ollvm编译出现的问题纪录