import { weixinSdk } from './weixin'; export type ClientGpsLocation = { province?: string; city?: string; district?: string; latitude: number; longitude: number; address?: string; }; /** 尝试获取客户端 GPS(微信 JSSDK / 浏览器 Geolocation),失败返回 null 不阻塞下单 */ export async function tryGetClientGpsLocation(): Promise { if (process.env.TARO_ENV === 'weapp') { try { const Taro = (await import('@tarojs/taro')).default; const loc = await new Promise<{ latitude: number; longitude: number }>((resolve, reject) => { Taro.getLocation({ type: 'gcj02', success: resolve, fail: reject, }); }); return { latitude: loc.latitude, longitude: loc.longitude }; } catch { return null; } } const loc = await weixinSdk.getLocation(); if (!loc) return null; return { latitude: loc.latitude, longitude: loc.longitude, }; }