const luxian = async() => {
markers.value=indexStore.markers
selectItem.value = indexStore.markers.find((p) => p.id == indexStore.markersIndex);
change_target();
await uni.getLocation({
type: 'gcj02',
success: async (res) => {
longitude.value = res.longitude;
latitude.value = res.latitude;
const result = await indexStore.useRoute_planning({ target: target.value.lon + ',' + target.value.lat, origin: longitude.value + ',' + latitude.value });
const distance = Math.round(result.data.distance / 100) / 10;
const title = distance + '公里 ' + Math.floor(result.data.duration / 60) + '分钟';
const targetObject = markers.value.find((p) => p.id === indexStore.markersIndex);
if (targetObject) {
// 执行修改操作
targetObject.callout = title;
} else {
console.error(`Object with id ${targetId} not found in markers array.`);
}
console.log(markers.value);
_mapContext.value.addMarkers({
markers: markers.value,
clear: true
});
console.log("执行")
polyline.value.points = result.data.polyline;
console.log('success结束');
},
fail: (e) => {
console.log('失败');
console.log('获取位置信息失败', e.errMsg);
},
complete: () => {
console.log(markers.value)
console.log('结束');
}
});
};
打印结果
[Object] [{"id":0,"latitude":28.32483,"longitude":112.935976,"iconPath":"/static/png/index/dian.png"...} at pages/index/luxian.nvue:289
结束 at pages/index/luxian.nvue:290 只执行complete
定位权限也提供了
1***@qq.com (作者)
解决了谢谢
2024-07-18 20:41