uniapp 获取当前定位(详细地址)打开导航

首先在项目中配置app模块配置


//获取当前位置
				uni.getLocation({
				  type: 'wgs84',
				  success: function (res) {
				    const latitude = res.latitude; // 纬度
				    const longitude = res.longitude; // 经度
				    uni.request({
				      url: 'https://restapi.amap.com/v3/geocode/regeo', // 高德地图逆地理编码API
				      data: {
				        key: '', // 替换为你的高德地图API Key
				        // location: `${longitude},${latitude}`,
						  location: `${116.692657},${39.918163}`,
				      },
				      success: function (response) {
				        if(response.data && response.data.regeocode) {
				          const city = response.data.regeocode.addressComponent.city;
				          // 这里可以根据需要将city进行进一步处理,例如赋值给data中的变量等
				        }
				      }
				    });
				  }
				});
	uni.getLocation({
					type: 'gcj02', // 返回可以用于uni.openLocation的经纬度,默认为wgs84的gps坐标
					success: function(res) {
						console.log('当前位置的经度:' + res.longitude,res,'---');
						console.log('当前位置的纬度:' + res.latitude);
						uni.openLocation({    //打开地图
							latitude: 40.805754, //纬度
							longitude: 111.665039, //经度
							name: "呼和浩特市回民区吕祖庙街",
							address: "内蒙古自治区呼和浩特市回民区吕祖庙街"
						});
					},
					fail: function(error) {
						console.error('获取位置失败:', error);
					}
				});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值