学无先后,达者为师

网站首页 编程语言 正文

uniapp 微信小程序获取当前位置的坐标

作者:maoge_666 更新时间: 2023-07-16 编程语言

在这里插入图片描述

在这里插入图片描述

data() {
	return {
		longitude: '', // 经度(当前用户位置)
		latitude: '',// 纬度(当前用户位置)
	}
},
onLoad: function (options) {
	this.getCurrentLocation()
},
methods: {
	//通过微信自带的方法获取到当前的经纬度
	getCurrentLocation() {
		let that = this 
		uni.getLocation({
			type: 'wgs84',// 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
			success: function(res) {
				console.log("当前位置信息:",res)
				that.longitude = res.longitude; // 经度,范围为-180~180,负数表示西经
				that.latitude = res.latitude;// 纬度,范围为-90~90,负数表示南纬
			},
			fail: function(error) {
				uni.showToast({
					title: '无法获取位置信息!无法使用位置功能',
					icon: 'none',
				})
			}
		});
	},
}

原文链接:https://blog.csdn.net/maoge_666/article/details/131579653

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新