<map style="width:100%;height:100vh;" :latitude="latitude" :longitude="longitude" :scale="scale" :markers="marker" @markertap="tan()">
onLoad() {
this.goMap()
},
//打开手机内置地图
toMap() {
console.log('点击导航')
uni.openLocation({
latitude: Number(this.latitude), //要去的纬度-地址
longitude: Number(this.longitude), //要去的经度-地址
address: this.address, //要去的具体地址
//此处踩坑的问题2:
//latitude 和 longitude的值一定要是number类型。
//所以传递的时候需要使用Number将其转换一下。
})
},
//获取位置授权
goMap() {
const that = this
// uniapp 需要先调取用户授权请求询问用户是否授权
uni.authorize({
scope: 'scope.userLocation',
success(res) {
uni.getLocation({
type: 'wgs84',
success: (res) => {
console.log(res)
console.log('纬度:' + res.latitude);
console.log('经度:' + res.longitude);
that.latitude = res.latitude
that.longitude = res.longitude
}
})
},
fail(err) {
uni.$showMsg('获取位置失败!')
}
})
}
uniapp微信小程序地图,获取位置授权,打开手机内置地图
猜你喜欢
转载自blog.csdn.net/qq_59175937/article/details/126936441
今日推荐
周排行