微信小程序如何使用天地图的逆地理编码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);
            }
        })
    },
相关推荐
tedcloud1232 小时前
UI-TARS-desktop部署教程:构建AI桌面自动化系统
服务器·前端·人工智能·ui·自动化·github
UXbot5 小时前
AI原型设计工具如何支持团队协作与快速迭代
前端·交互·个人开发·ai编程·原型模式
ZC跨境爬虫6 小时前
跟着MDN学HTML_day_48:(Node接口)
前端·javascript·ui·html·音视频
PieroPc8 小时前
CAMWATCH — 局域网摄像头监控系统 Fastapi + html
前端·python·html·fastapi·监控
巴巴博一9 小时前
2026 最新:Trae / Cursor 一键接入 taste-skill 完整教程(让 AI 前端告别“AI 味”)
前端·ai·ai编程
kyriewen9 小时前
半夜三点线上崩了,AI替我背了锅——用AI排错,五分钟定位三年老bug
前端·javascript·ai编程
kyriewen9 小时前
我让 AI 当了 24 小时全年无休的“毒舌考官”
前端·ci/cd·ai编程
hexu_blog9 小时前
vue+java实现图片批量压缩
java·前端·vue.js
IT_陈寒10 小时前
为什么你应该学习JavaScript?
前端·人工智能·后端
lifejump10 小时前
Empire(帝国)CMS 7.5 XSS注入
前端·安全·xss