微信小程序 获取地址信息(uniapp)

参考API地址:微信小程序JavaScript SDK | 腾讯位置服务 

<script>	
    // 引入SDK核心类,js文件根据自己业务,位置可自行放置
    var QQMapWX = require('../../js/uploadImg/qqmap-wx-jssdk.js');
    export default {
        data(){
            return{
                qqmapsdk:''
            }
        },
        onLoad(opention) { 
			 this.qqmapsdk = new QQMapWX({
					key: '腾讯地图的key'
				});
		},
		onShow(){
			var _this=this;
			uni.getLocation({
				success(res) { 
					// 调用接口
					_this.qqmapsdk.reverseGeocoder({
						location: {
						  latitude: res.latitude,
						  longitude: res.longitude
						}, 
						fail: function (res) {
							console.log(res);
						},
						complete: function (res) {
							console.log(res);
							if(!res.status){
								console.log('成功了');
								console.log(
								
								);
								res.result.address_component.city
							}
						}
					}) 
				},
				fail(err) {
					reject(location); //获取失败则返回经纬坐标为0
				}
			})
			
		},
    
    }

res里面即可查看所有地址相关信息 

相关推荐

  1. 程序地图

    2024-01-06 12:34:02       6 阅读

最近更新

  1. TCP协议是安全的吗?

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

    2024-01-06 12:34:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-06 12:34:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-06 12:34:02       18 阅读

热门阅读

  1. 详细介绍Spring Boot 和 Spring 有什么区别

    2024-01-06 12:34:02       27 阅读
  2. Ceph分布式存储

    2024-01-06 12:34:02       25 阅读
  3. 基于长短期神经网络lstm的求解方程

    2024-01-06 12:34:02       35 阅读
  4. C++面对对象编程

    2024-01-06 12:34:02       33 阅读
  5. instanceof 能够正确判断对象的原理是什么?

    2024-01-06 12:34:02       36 阅读
  6. copilot插件使用介绍

    2024-01-06 12:34:02       36 阅读
  7. 分享一个idea插件MyBatisX的Bug

    2024-01-06 12:34:02       39 阅读