uniapp WeChat applet to obtain the coordinates of the current location

insert image description here

insert image description here

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

Guess you like

Origin blog.csdn.net/maoge_666/article/details/131579653