/** * 获取当前页面路径 * @returns 当前页面路径 */ export function getCurrentPath() { const pages = getCurrentPages() const currentPage = pages[pages.length - 1] return currentPage.route || '' } /** * 检测当前环境是否为微信小程序 */ export function isWxMiniProgram() { return new Promise((resolve, reject) => { const apltInfo = uni.getDeviceInfo() console.log(apltInfo, '当前环境=======================') if (apltInfo.platform === 'windows') { useGlobalToast().show('不支持电脑操作地址,请使用手机打开') reject(new Error('不支持电脑操作地址,请使用手机打开')) } resolve(1) }) } /** * 将角度转换为弧度 */ function toRadians(degrees: number): number { return degrees * Math.PI / 180 } /** * 将弧度转换为角度 */ function toDegrees(radians: number): number { return radians * 180 / Math.PI } /** * 计算两个经纬度的中心点(球面插值法) * 适用于任意距离,考虑地球曲率,更精确 * * @param pointA 第一个经纬度坐标 * @param pointB 第二个经纬度坐标 * @returns 中心点经纬度坐标 */ export function calculateCenterPointSpherical( pointA: { lat: number, lng: number }, pointB: { lat: number, lng: number }, ): { lat: number, lng: number } { // 将经纬度转换为弧度 const lat1 = toRadians(pointA.lat) const lng1 = toRadians(pointA.lng) const lat2 = toRadians(pointB.lat) const lng2 = toRadians(pointB.lng) // 计算纬度的差值 const dLng = lng2 - lng1 // 使用球面插值公式计算中心点 const Bx = Math.cos(lat2) * Math.cos(dLng) const By = Math.cos(lat2) * Math.sin(dLng) const centerLat = Math.atan2( Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By), ) const centerLng = lng1 + Math.atan2(By, Math.cos(lat1) + Bx) // 将结果转换回角度 return { lat: toDegrees(centerLat), lng: toDegrees(centerLng), } }