managarten/apps-archived/memoro/apps/mobile/features/location/utils/locationHelpers.ts
Till-JS 61d181fbc2 chore: archive inactive projects to apps-archived/
Move inactive projects out of active workspace:
- bauntown (community website)
- maerchenzauber (AI story generation)
- memoro (voice memo app)
- news (news aggregation)
- nutriphi (nutrition tracking)
- reader (reading app)
- uload (URL shortener)
- wisekeep (AI wisdom extraction)

Update CLAUDE.md documentation:
- Add presi to active projects
- Document archived projects section
- Update workspace configuration

Archived apps can be re-activated by moving back to apps/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 07:03:59 +01:00

72 lines
2 KiB
TypeScript

/**
* Helper functions for working with location data
*/
/**
* Parse PostGIS POINT string to coordinates
* @param pointString - PostGIS POINT format: "POINT(longitude latitude)"
* @returns Object with latitude and longitude or null if invalid
*/
export function parsePostGISPoint(
pointString: string | null | undefined
): { latitude: number; longitude: number } | null {
if (!pointString) return null;
// Match POINT(longitude latitude) format
const match = pointString.match(/POINT\(([-\d.]+)\s+([-\d.]+)\)/);
if (!match) return null;
const longitude = parseFloat(match[1]);
const latitude = parseFloat(match[2]);
// Validate coordinates
if (isNaN(longitude) || isNaN(latitude)) return null;
if (latitude < -90 || latitude > 90) return null;
if (longitude < -180 || longitude > 180) return null;
return { latitude, longitude };
}
/**
* Convert coordinates to PostGIS POINT format
* @param latitude
* @param longitude
* @returns PostGIS POINT string
*/
export function toPostGISPoint(latitude: number, longitude: number): string {
return `POINT(${longitude} ${latitude})`;
}
/**
* Get location data from memo using the PostGIS location field and address from metadata
* @param memo - The memo object
* @returns Location data with latitude, longitude, and address or null
*/
export function getMemoLocation(
memo: any
): { latitude?: number; longitude?: number; address?: any } | null {
// Check if we have address data in metadata
const hasAddress = memo?.metadata?.address;
// Parse location coordinates if available
const parsed = memo?.location ? parsePostGISPoint(memo.location) : null;
// If we have neither coordinates nor address, return null
if (!parsed && !hasAddress) {
return null;
}
// Build result with available data
const result: { latitude?: number; longitude?: number; address?: any } = {};
if (parsed) {
result.latitude = parsed.latitude;
result.longitude = parsed.longitude;
}
if (hasAddress) {
result.address = memo.metadata.address;
}
return result;
}