日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

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

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新