function normalizeAddress(location = {}) { const address = location.address || '' if (address) { return address } const parts = [ location.province, location.city, location.district, location.street, location.streetNum, location.poiName ].filter(Boolean) return parts.join(' ') } function normalizeLocation(location = {}) { return { latitude: Number(location.latitude || 0), longitude: Number(location.longitude || 0), accuracy: Number(location.accuracy || 0), address: normalizeAddress(location), province: location.province || '', city: location.city || '', district: location.district || '', street: location.street || '', streetNum: location.streetNum || '', poiName: location.poiName || '' } } export function formatLocationMessage(location = {}) { const normalized = normalizeLocation(location) const address = normalized.address || '未解析到地址' return [ `纬度:${normalized.latitude.toFixed(6)}`, `经度:${normalized.longitude.toFixed(6)}`, `精度:${normalized.accuracy || 0}米`, `地址:${address}` ].join('\n') } export function getCurrentLocation() { return new Promise((resolve, reject) => { uni.getLocation({ type: 'gcj02', geocode: true, isHighAccuracy: true, highAccuracyExpireTime: 4000, success(res) { resolve(normalizeLocation(res)) }, fail(error) { reject(error) } }) }) } export function requestStartupLocationPermission() { return getCurrentLocation().catch((error) => { console.log('Location permission request skipped or denied', error) return null }) }