Files
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

29 lines
1.1 KiB
TypeScript

export function makeLatLngLike(lat: number, lng: number): google.maps.LatLng {
return {
lat: () => lat,
lng: () => lng,
equals: (other: google.maps.LatLng) => other.lat() === lat && other.lng() === lng,
toJSON: () => ({ lat, lng }),
toString: () => `(${lat}, ${lng})`,
toUrlValue: (precision?: number) => {
const p = typeof precision === 'number' ? precision : 6;
return `${lat.toFixed(p)},${lng.toFixed(p)}`;
},
} as google.maps.LatLng;
}
export function readLatLngLike(
loc: google.maps.LatLng | google.maps.LatLngLiteral | null | undefined,
): google.maps.LatLngLiteral | null {
if (!loc) return null;
const record = loc as unknown as {
lat?: number | (() => number);
lng?: number | (() => number);
};
const lat = typeof record.lat === 'function' ? record.lat() : record.lat;
const lng = typeof record.lng === 'function' ? record.lng() : record.lng;
if (typeof lat !== 'number' || typeof lng !== 'number') return null;
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return null;
return { lat, lng };
}