// 计算点位距离 export const distanceCalculate = (num) => { const num_ = Number(num); if (typeof num_ === 'number') { if (num_ < 1000) { return `${num_.toFixed(1)}米` } else { const n = (num_ / 1000).toFixed(1); return `${n}公里` }; } return num_ || num } // 拨打电话 export const PhoneCall = (tel) => { if (tel) { uni.makePhoneCall({ phoneNumber: tel + '' }); } else { uni.showToast({ title: '暂未设置电话' }); } } // 导航 export const getMapLocation = (parmas = {}) => { const { latitude, longitude, name, detailedAddress } = parmas uni.openLocation({ latitude: parseFloat(latitude), // 要去的地址经度,浮点数 longitude: parseFloat(longitude), // 要去的地址纬度,浮点数 name: name, // 位置名 address: detailedAddress, // 要去的地址详情说明 scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大 }); } export const getLocation = () => { return new Promise((resolve, reject) => { try { uni.getLocation({ type: 'wgs84', // 返回可以用于uni.openLocation的经纬度 success: (res) => { console.log("getLocation = " , res) // this.selfLatitude = res.longitude; // this.selfLongitude = res.latitude; resolve(res) }, fail: (err) => { console.log('获取位置失败2 :', err); }, fail: () => { console.log('获取位置失败3 :'); } }); } catch (error) { console.log('获取位置失败 1:', error); //TODO handle the exception } }) }