Overview
The location utilities provide functions for converting place names to coordinates (geocoding) and formatting location strings for display.geocode
Converts a place name or address into geographic coordinates using the OpenStreetMap Nominatim API.Parameters
The place name or address to geocode. Can be a city name, full address, or any location description (e.g., “New York”, “1600 Pennsylvania Avenue”, “Tokyo, Japan”).
Returns
A fetch Response object. On success, the JSON data contains an array of location results.
The latitude of the location.
The longitude of the location.
The full formatted address/location name.
The bounding box coordinates [south, north, west, east].
API Endpoint
q: The place name to search forformat: “json” (response format)limit: “1” (number of results)
Accept: “application/json”User-Agent: “Praydo/0.4 (https://github.com/agnanp/praydo; [email protected])“
Example
Error Handling
formattedLocation
Formats a location string by extracting the first two parts, capitalizing properly, and cleaning up the format.Parameters
The location string to format, typically a comma-separated address.
Returns
A formatted location string containing only the first two parts, with proper capitalization.
Example
Behavior
- Extracts only the first two comma-separated parts
- Capitalizes the first letter of each word
- Converts remaining letters to lowercase
- Trims whitespace from each part
- Returns empty string if input is empty or null