首页 附近技师定位距离
This commit is contained in:
parent
f26341c57b
commit
6ca920531e
|
@ -118,10 +118,10 @@
|
|||
<view class="fujin-view" v-for="(item,index) in nearbyTechnician" :key="index" @click="goOrder(item)">
|
||||
<view class="index-fujin-view">
|
||||
<image class="index-fujin-view-img" :src="item.artificerImg" mode=""></image>
|
||||
<!-- <view class="index-fujin-view-text">
|
||||
<view class="index-fujin-view-text">
|
||||
<image src="../../static/orderDetail/dingwei.png" mode="w"></image>
|
||||
<span>1.2km</span>
|
||||
</view> -->
|
||||
<span>{{item.dingwei}}km</span>
|
||||
</view>
|
||||
</view>
|
||||
<view class="index-fujin-jie">
|
||||
<view class="index-fujin-jie-view">
|
||||
|
@ -479,6 +479,23 @@
|
|||
// }
|
||||
},
|
||||
methods: {
|
||||
calculateDistance(lat1, lon1, lat2, lon2) {
|
||||
// 将经纬度转换为弧度
|
||||
const radLat1 = lat1 * (Math.PI / 180);
|
||||
const radLat2 = lat2 * (Math.PI / 180);
|
||||
const radLon1 = lon1 * (Math.PI / 180);
|
||||
const radLon2 = lon2 * (Math.PI / 180);
|
||||
const a = radLat1 - radLat2;
|
||||
const b = radLon1 - radLon2;
|
||||
|
||||
// 使用海里公式计算距离
|
||||
const Haversine = Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2);
|
||||
const distance = 2 * 6371 * Math.atan2(Math.sqrt(Haversine), Math.sqrt(1 - Haversine));
|
||||
|
||||
// 返回单位为公里的距离
|
||||
return distance;
|
||||
|
||||
},
|
||||
// 开启订阅消息
|
||||
openMsg() {
|
||||
console.log('订阅消息')
|
||||
|
@ -749,8 +766,32 @@
|
|||
this.$Request.get("/app/artificer/getHomeArtificerList",data).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.starTechnician = res.startData.list;
|
||||
this.nearbyTechnician=res.nearData.list
|
||||
console.log("starTechnician",res.startData.list)
|
||||
this.nearbyTechnician=res.nearData.list;
|
||||
const myLatitude = this.latitude; // 当前位置纬度
|
||||
const myLongitude = this.longitude; // 当前位置经度
|
||||
// const targetLatitude = 39.919; // 目标位置纬度
|
||||
// const targetLongitude = 116.486; // 目标位置经度
|
||||
const targetLatitude = ''; // 目标位置纬度
|
||||
const targetLongitude =''; // 目标位置经度
|
||||
for(var i=0;i<this.nearbyTechnician.length;i++){
|
||||
// targetLongitude=this.nearbyTechnician[i].longitude;
|
||||
// targetLatitude=this.nearbyTechnician[i].latitude
|
||||
const distance = this.calculateDistance(
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.nearbyTechnician[i].latitude,
|
||||
this.nearbyTechnician[i].longitude
|
||||
);
|
||||
this.nearbyTechnician[i].dingwei= distance.toFixed(1)
|
||||
console.log(`距离为: ${distance.toFixed(1)} km`);
|
||||
}
|
||||
// const distance = this.calculateDistance(
|
||||
// myLatitude,
|
||||
// myLongitude,
|
||||
// targetLatitude,
|
||||
// targetLongitude
|
||||
// );
|
||||
console.log("starTechnician===>",this.nearbyTechnician)
|
||||
// this.classifyId = res.data[0].id;
|
||||
// this.getorderlist('')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue