记 在微信小程序中 调用高德api 出现 errCode:10009

一、前言

目的:为了获取详细地址中文

二、问题

查看错误信息列表

// 前人书写的代码:

const url = `https://restapi.amap.com/v3/geocode/regeo?location=${经纬度}&key=${绑定平台的key}`

const [error, res] = await uni.request({ url });

// 这样会出现 如下情况

/**
 *   info: "USERKEY_PLAT_NOMATCH"
 *   infocode: "10009"
 *   status: "0"
 */


三、寻求解决方法

1、微信小程序相关插件下载 提供在微信小程序中使用高德、客户业务数据的功能。

2、导入到项目

3、开始梭哈代码

/**
 *  amapTools.js 文件
*/


import amap from "@/js_sdk/amap/amap-wx.130.js"; // 下载的插件存放位置
import { MAP_KEY } from "@/env.js"; // 存放高德key的目录

const Amap = new amap.AMapWX({  
  key: MAP_KEY
});  

export default Amap;

4、在vue文件中调用

<script>
import Amap from "@/common/utils/amapTools";

export default {

    data() {
        Amap,
        // 自行替换经纬度
        lng: "xxx", // 自行替换
        lat: "xxx", // 自行替换
    },

    methods: {
        getAddress() {
            // 获取位置信息
            this.Amap.getRegeo({
                location: `${this.lng},${this.lat}`,
                success: (res) => {
                  // console.log("res -0-0", res);

                  let data = res[0].regeocodeData.addressComponent;

                },
                fail: (err) => {
                  // console.log("err-0-0", err);
                },
             });
        },
        /**
		 * searchVal: 搜索值
		 * cityCode:城市code  相关参考可以查阅 
         * https://lbs.amap.com/api/webservice/guide/api-advanced/inputtips
		 */
        inputTips(searchVal, cityCode) {
            // 地点搜索
            this.Amap.getInputtips({
                keywords: searchVal,
                city: cityCode,
                citylimit: true,
                location: `${this.lng},${this.lat}`,
                success: (res) => {
                  // console.log("getInputtips -0-0 res", res);
                },
                fail: (err) => {
                  // console.log("getInputtips -0-0 err", err);
                },
            });
        }
    
    }


}


</script>

5、如此这般之后,成功跑通

{info: "OK",infocode: "10000",status: "1"}

四、结尾

如有打错的地方,请高抬贵手

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值