<button @click="goJ">点击获取经纬度</button>
<p>经度{{latitude}}</p>
<p>纬度{{longitude}}</p>
methods: {
goJ() {
let that = this
console.log(2);
uni.getLocation({
type: 'wgs84',
enableHighAccuracy: true,
success: function(res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
that.latitude = res.latitude
that.longitude = res.longitude
console.log(that.latitude, 'oo');
uni.showToast({
title: '成功',
icon: 'success'
});
},
fail: err => {
uni.showToast({
title: err.errMsg,
icon: 'error'
});
}
});
}
}
uniapp求当前位置的经纬度。我这么写,然后在手机自带的浏览器上可以获取到经纬度,但是手机上的其他浏览器类似火狐浏览器不能获取到经纬度。然后我在PC端运行,除了谷歌浏览器不能运行,Edge和火狐可以运行获取到经纬度