uniapp开发小程序的时候 用到map组件渲染 使用uni.openLocation 打开外部导航的时候 微信开发者工具可以触发地图点击事件, 但是真机测试点击地图触发不了没响应 只有点击不是地图的地方才能触发方法、
页面以及js如下
<view class="storeMap" @tap="handleMapLocation">
<view class="map">
<map style="border-radius: 20rpx 20rpx 0 0 / 20rpx 20rpx 0 0 ;" :latitude="shoppdata.latitude"
:longitude="shoppdata.longitude" :enable-3D="true" :markers="covers"></map>
</view>
<view class="mapbottom">
<view class="left">
去这里
</view>
<view class="img">
<image src="../../static/xiyoujiantou.png" mode=""></image>
</view>
</view>
</view>
handleMapLocation() {
var that = this
// 获取定位信息
uni.getLocation({
type: 'wgs84', //返回可以用于uni.openLocation的经纬度
// 用户允许获取定位
success: function(res) {
console.log(res, '经纬度===>')
if (res.errMsg == "getLocation:ok") {
console.log('shoppdata', that.shoppdata)
uni.openLocation({
// 传入你要去的纬度
latitude: Number(that.shoppdata.latitude),
// // 传入你要去的经度
longitude: Number(that.shoppdata.longitude),
// 传入你要去的地址信息 不填则为空
// address: address,
// 缩放大小
scale: 18,
success: function() {
console.log('导航成功回调success');
}
});
}
},
// 用户拒绝获取定位后 再次点击触发
fail: function(res) {
console.log(res)
if (res.errMsg == "getLocation:fail auth deny") {
uni.showModal({
content: '检测到您没打开获取信息功能权限,是否去设置打开?',
confirmText: "确认",
cancelText: '取消',
success: (res) => {
if (res.confirm) {
uni.openSetting({
success: (res) => {
console.log('确定');
}
})
} else {
console.log('取消');
return false;
}
}
})
}
}
});
},