uniapp,微信小程序点击按钮打开地图进行导航

uniapp示例:

<view class="order-contact-item" style="width:50%;text-align: center;" @tap="openMapNavigation">导航商家</view>

 

//js函数打开导航
openMapNavigation() {
var that = this;
uni.getLocation({
type: 'gcj02',
success: (res) => {
// 当前位置
const latitude = res.latitude;
const longitude = res.longitude;

// 目标位置
const destinationLatitude = parseFloat(that.goods.latitude);
const destinationLongitude = parseFloat(that.goods.longitude);

uni.openLocation({
latitude: destinationLatitude,
longitude: destinationLongitude,
name: that.goods.business_name,
address: that.goods.business_address,
scale: 18,
success(res) {
console.log('打开地图成功',that.goods.latitude);
},
fail(err) {
console.error('打开地图失败', err);
}
});
},
fail: (err) => {
console.error('获取当前位置失败', err);
}
});
}

posted @ 2023-06-27 18:17  幽暗天琴  阅读(658)  评论(0编辑  收藏  举报