当前位置:网站首页>高德地图jsapi不生效 INVALID_USER_SCODE
高德地图jsapi不生效 INVALID_USER_SCODE
2022-07-30 00:18:00 【sunddy_x】
一段时间未使用高德地图开发web网页,今天需要使用它的POI搜索功能,按照老规矩,登录高德开发者,打开控制台,新建应用,此时出现了新的东西—安全密钥
,本文的主角。
此时,它并没有引起我的注意,我依旧按着步骤,在vue中引入jsapi包,注册插件,加载高德api
AMapLoader.load({
"key": "你的key",
"version": "2.0",
"plugins": ['AMap.PlaceSearch'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
}).then((AMap) => {
const {
Map, PlaceSearch } = AMap
const amap = new Map('amap', {
center: [120.980795, 31.385476],
zoom: 10,
resizeEnable: true
});
const placeSearch = new PlaceSearch({
pageSize: 10, // 单页显示结果条数
pageIndex: 1, // 页码
city: "010", // 兴趣点城市
citylimit: true, //是否强制限制在设置的城市内搜索
map: amap, // 展现结果的地图实例
autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
});
//关键字查询
placeSearch.search('药房', (status, result) => {
console.log(status);
console.log(result);
});
})
上述代码就是调用高德地图的POI搜索功能,示例是正常的,而到项目中就显示不出标注点,下图是官网示例:
遇到问题那就解决问题,首先把AMap,PlaceSearch都打印出来,发现对象是确实存在的,说明引入没有问题。然后在PlaceSearch的 search
方法回调中打印 status
和 result
,status是 error
,result是 INVALID_USER_SCODE
,翻译过来是无效的用户范围
。百度这个关键词,翻了一些不相关的文章后,找到一篇有用的内容,高德地图js api出现INVALID_USER_SCODE。
还记得最开始提到的安全密钥
嘛,高德地图自2021年12月02日升级,升级之后所申请的 key 必须配备安全密钥 jscode 一起使用
。问题就这么简单,官网地址,安全密钥的使用方法有两种,官网有介绍,这里就写一下vue3项目开发环境的写法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover" />
<title></title>
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode:'你的密钥',
}
</script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
刷新页面就有标注点了
边栏推荐
猜你喜欢
i.MX6U-driver development-3-new character driver
Worthington Dissociation Enzymes: Collagenase and Four Basic Profiles
更换可执行文件glibc版本的某一次挣扎
3 tips for using hot events to create press releases?A must-see for self-media people
“ 我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你 ”
多商户商城系统功能拆解18讲-平台端商家售后
外包干了五年,废了...
【分层强化学习】survey
EA&UML日拱一卒-多任务编程超入门-(8)多任务安全的数据类
"The lighthouse factory" of China path: smart roll out from point to surface
随机推荐
vmtouch——Linux下的文件缓存管理神器
Unity Addressables
How do we-media people create explosive articles?These 3 types of articles are most likely to explode
“ 我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你 ”
【集训DAY16】KC ‘ s Stars【dfs】
某团实习面经
月薪15k的阿里测试岗,面试原来这么简单
字符串替换空格
[Cloud native Kubernetes] Build a Kubernetes cluster in binary (middle) - deploy node nodes
Worthington's tried and tested cell isolation system protocols
关于MySQL索引的一些个人理解(部分参考MySQL45讲)
Go日志库——logrus
call、apply 以及 bind 的区别和用法
At the age of 29, I was fired from a functional test. Can't find a job after 2 months of interviews?
Worthington弹性蛋白酶&透明质酸酶简介
From the perspective: the interviewer interview function test engineer mainly inspects what ability?
Codeforces Round #805 (Div. 3) Summary
X64 mfc140u.dll文件缺失->应用程序无法正常启动(0xc000007b)解决方法
The difference and usage of call, apply and bind
图像的IO操作