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

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

天地图逆地理编码api

1、使用wx.request 发送请求

 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);
            }
        })
    },

相关推荐

  1. 程序如何使用天地地理编码api

    2024-01-07 21:54:01       38 阅读
  2. 程序常用api

    2024-01-07 21:54:01       14 阅读
  3. 程序vant使用

    2024-01-07 21:54:01       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-07 21:54:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-07 21:54:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-07 21:54:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-07 21:54:01       18 阅读

热门阅读

  1. spring 项目配置中一些问题和使用方法

    2024-01-07 21:54:01       33 阅读
  2. DevOps(7)

    2024-01-07 21:54:01       32 阅读
  3. 怎么实现一个类型判断函数

    2024-01-07 21:54:01       32 阅读
  4. 深入理解Vue3中的watch与watchEffect的使用与区别

    2024-01-07 21:54:01       33 阅读