微信小程序如何使用天地图的逆地理编码api

本文只介绍如何使用天地图api,如若要显示天地图,使用 web-view

天地图逆地理编码api

1、使用wx.request 发送请求

js 复制代码
 getLocation() {
       wx.getLocation({
            type: 'gcj02',
            success: (res) => {
                // 调用天地图逆地理编码api
                this.initTianDiMap(res.longitude, res.latitude)
            },
            fail: (err) => {
                 console.log('err', err);
            }
        })
     }
     
     initTianDiMap(longitude, latitude) {
        let that = this
        wx.request({
            url: 'http://api.tianditu.gov.cn/geocoder', //逆地理编码接口地址
            data: {
                postStr: JSON.stringify({'lon':longitude,'lat':latitude,'ver':1}),
                type: 'geocode',
                tk: '2826428fe95fecce4433373ebf0d9945'
            },  //逆地理编码接口参数
            success: function (res) {
                console.log(143, res.data);
            },
            fail: function (res) {
                console.log(res.errMsg);
            }
        })
    },
相关推荐
前端fighter8 小时前
2026年前端面试题总结(pdf版)
前端·pdf
谢小飞8 小时前
运维加了个参数,我们的网页挂掉了
前端·浏览器
CoderYanger9 小时前
Java EE 进阶:12.Spring AOP(第二弹)
java·前端·数据库·spring boot·spring·java-ee·mybatis
用户693717500138412 小时前
大模型蒸馏到底在蒸什么?一篇文章搞懂知识蒸馏概念
前端·后端·github
徐小夕12 小时前
实测 10 个前端 UI 生成开源 Skill|AI 输出直达上线标准
前端·vue.js·github
tong_li12 小时前
给娃做个 AI 陪写作业助手:LangChain4j 入门(八):AI 知道这字哪课学的(SQLite 结构化查询入门)
前端·langchain
用户693717500138412 小时前
当 Claude 开始反对蒸馏,我想起了那 700 万份盗版书籍
前端·后端·面试
zhanlang021713 小时前
HTML 零基础入门到企业实战全套教程【10.1】综合实战|从零开发静态企业官网:需求分析、页面结构规划、素材准备
前端·html
Bczheng113 小时前
浏览器访问本地html和服务器html的流程
前端
金八梭13 小时前
格斗对决v4.5
前端·css·自动化·html·css3