@asksoma/location
v1.1.2
Published
AskSoma location stack — city geocode (Open-Meteo → Nominatim → Photon), Google Maps link parse, IANA/TZ helpers, GPS detect, and React LocationSearch (Leaflet). No Google Places API key.
Downloads
34
Readme
@asksoma/location
AskSoma place search — no Google Places API key.
City autocomplete (Open-Meteo → Nominatim → Photon), Google Maps / goo.gl paste, Leaflet Advanced modal, IANA timezone helpers, GPS detect, and React pickers.
Install
npm i @asksoma/location leaflet lucide-react
# or via partner kit
npm i @asksoma/partner@latestHeadless (Node / Deno / browser)
import {
geocodeWithFallback,
geocodeCitySilent,
parseGoogleMapsLink,
inferIanaFromLocation,
resolveBirthIanaTimezone,
resolveChartLocation,
resolveChartLocationAsync,
detectCurrentCity,
locationCspConnectSrc,
} from '@asksoma/location';
const hits = await geocodeWithFallback('Mumbai', 10);
// Sync (muhurat / event pickers — snappy; infer IANA if Open-Meteo omitted TZ)
const chart = resolveChartLocation({
name: hits[0].display_name,
lat: +hits[0].lat,
lng: +hits[0].lon,
timezone: hits[0].timezone,
});
// Async (birth charts — enrichTimezone defaults true when Maps/Nominatim omit IANA)
const birth = await resolveChartLocationAsync({
name: hits[0].display_name,
lat: +hits[0].lat,
lng: +hits[0].lon,
timezone: hits[0].timezone,
enrichTimezone: true,
});
// → feed birth.lat / birth.lon / birth.tz into AskSomaClient.muhurat({ chart })TZ policy: sync resolveChartLocation for UI speed; async enrich for birth/legal timing. See docs/LOCATION_SDK_HANDOFF.md.
React
import { LocationSearch, BirthLocationPicker } from '@asksoma/location/react';
<LocationSearch
onLocationSelect={(name, lat, lng, countryCode, timezone) => {
const resolved = resolveChartLocation({ name, lat, lng, countryCode, timezone });
// …
}}
/>
<BirthLocationPicker
showCurrentLocation
onSelect={(loc, iana) => { /* birth_data.birthLocation + IANA */ }}
/>Design split
| Module | Runs where | Why | |--------|------------|-----| | Headless geocode + Maps parse + TZ | Node / Deno / browser | Partners, bots, workers | | React LocationSearch / BirthLocationPicker | Browser only | Leaflet + OSM + Advanced modal |
Do not put Leaflet inside @asksoma/astro-client — keep location separate so Muhurat embed can swap manual lat/lon for the real picker without pulling chat/astro.
CSP
Allowlist (see locationCspConnectSrc()): Open-Meteo, Nominatim, Photon, *.tile.openstreetmap.org, ipapi.co.
Vite proxy (dev)
proxy: {
'/geocoding-proxy/open-meteo': { target: 'https://geocoding-api.open-meteo.com', changeOrigin: true, rewrite: (p) => p.replace(/^\/geocoding-proxy\/open-meteo/, '') },
'/geocoding-proxy/nominatim': { target: 'https://nominatim.openstreetmap.org', changeOrigin: true, rewrite: (p) => p.replace(/^\/geocoding-proxy\/nominatim/, '') },
'/geocoding-proxy/photon': { target: 'https://photon.komoot.io', changeOrigin: true, rewrite: (p) => p.replace(/^\/geocoding-proxy\/photon/, '') },
}