How it works
- You enter a city name in the input field.
- The app encodes the name and sends a request to the Open-Meteo Geocoding API.
- The API returns the best-matching result, including latitude, longitude, display name, and country.
- Those coordinates are passed directly to the weather forecast API.
Geocoding API URL pattern
count=1 parameter limits the response to the single best match. The city name is percent-encoded with encodeURIComponent before being appended to the URL.
Data returned
The app extracts the following fields fromgeoData.results[0]:
| Field | Description |
|---|---|
latitude | Decimal latitude of the city |
longitude | Decimal longitude of the city |
name | Canonical city name (e.g. “Paris”) |
country | Country name (e.g. “France”) |
name and country fields are combined into a display string ("Paris, France") stored in currentCityDisplay and shown above the temperature in the current weather view.
Code snippet
Error handling
City not found
If the API returns an emptyresults array, the app displays “City not found!” in the weather display area and stops further execution. No forecast request is made.
Network errors
If thefetch call throws (for example, due to a lost internet connection or a DNS failure), the catch block displays “Connection error. Please try again.”
The app does not retry failed requests automatically. If you see a connection error, check your internet connection and submit the form again.
Tips for accurate results
- Prefer the anglicised or local-language spelling that the geocoding service recognises (e.g. “Munich” or “München”).
- For cities that share a name, appending the country or region (e.g. “Springfield, Illinois”) improves accuracy.
- The geocoding API is case-insensitive, so “london”, “London”, and “LONDON” all return the same result.