任意选了起点或者终点的地址后,两个会同步

源码终点地址是确定的,我将终点地址也和起点地址一样改为了可以选择的,但是代码用的一样的,就出现了两者共用地址的情况,应该是有个变量没设置好,但是初学者不懂怎么改,希望大家帮忙看看怎么修改这个地址选取的代码才能让两者不同步而是分开选
代码图片如下

任意选了起点或者终点的地址后,两个会同步


m0_74195216 下午好🌅🌅🌅
本答案参考ChatGPT-3.5
问题是希望在微信小程序导航功能中,选取起点和终点地址设置时可以分别选取不同的地址,而不是同步选取相同的地址。根据提供的代码,需要修改选择地址的逻辑。
解决方案如下:
以下是修改后的代码示例:
Page({
data: {
startAddress: '', // 保存起点地址的变量
endAddress: '', // 保存终点地址的变量
},
_pickStartAddress:function(e) {
var that this;
console.log("选取起点地址,e");
let latitude that.data.location.latitude;
let longitude that.data.location.longitude;
console.log("latitude",latitude);
console.log("longitude",longitude);
this.getuserLocation();
// 根据选择的起点地址设置起点地址变量
this.setData({
startAddress: e.detail.address, // 这里根据实际的地址数据设置
});
},
_pickEndAddress:function(e) {
var that this;
console.log("选取终点地址,e");
let latitude that.data.location.latitude;
let longitude that.data.location.longitude;
console.log("latitude",latitude);
console.log("longitude",longitude);
this.getuserLocation();
// 根据选择的终点地址设置终点地址变量
this.setData({
endAddress: e.detail.address, // 这里根据实际的地址数据设置
});
},
navigate:function() {
// 使用起点和终点地址变量进行导航功能
const startAddress = this.data.startAddress;
const endAddress = this.data.endAddress;
// 进行导航功能的具体实现
// ...
}
});
通过以上修改,起点和终点地址的选择逻辑被分开,每个地址都可以单独选取,并且保存在对应的变量中。在导航功能中,可以使用起点和终点地址的变量来进行导航操作。这样就能够使起点和终点地址可以分别选取不同的地址而不是同步选取相同的地址。