Sunshine
Difficulty: Hard
Build a simple weather app that allows users to view the current weather at their location and search for places to check their weather conditions. The app will use Open-Meteo's free Geocoding API for location search and Forecast API for fetching weather data. This challenge tests API integration, state management, UI responsiveness, and handling concurrency when making multiple API requests.
App Structure
- Search Bar – Allows users to type in a prefix for place names and fetch matching places.
- Current Location Weather – Displays the current weather at the user's detected location. If location access is denied, this section is hidden.
- Favorite Places Weather – Displays weather for places users have added as favorites.
Requirements
Fetch Current Location Weather
- On app launch, request location access permission. If granted, retrieve the user’s latitude and longitude.
- Use the Forecast API to fetch the weather data, and display:
- Label: "Your Location"
- Current Temperature
- Weather Condition Summary (derived from weather code - see API docs below for more info)
Search for Places
- Implement a search bar to allow users to search for places dynamically. Use the Geocoding API to fetch matching places.
- Display results in a list with:
- Place Name
- Region Name: The first available and non-empty value from the following fields:
admin1,admin2,admin3,country. - "Add" Button to add the place to favorites.
- Debounce the search input to limit API requests, adding a 300ms delay after the user stops typing. Additionally, consider waiting until at least 3 characters are entered before making a request to improve search accuracy and reduce unnecessary calls.
Fetch and Display Favorite Places Weather
- When a place is added to favorites, use its latitude and longitude to fetch the current weather using the Forecast API.
- Display each favorite place’s weather in a section under Favorite Places, showing:
- Place Name
- Current Temperature
- Weather Condition Summary (derived from weather code - see API docs below for more info)
- (Optional) A weather emoji representing the current condition to enhance glanceability.
- If there are multiple favorite places, make concurrent API calls and update the UI dynamically.
Persist Favorite Places
Store the favorite places' name, latitude, and longitude locally. On next app launch, restore the stored places and fetch their weather data immediately.
API Doc
Place Search
GET https://geocoding-api.open-meteo.com/v1/search accepts a search term and returns a list of matching locations. URL parameters are listed below:
| Parameter | Format | Required | Default | Description |
|---|---|---|---|---|
name |
String | Yes | - | String to search for. An empty string or only 1 character will return an empty result. 2 characters will only match exact locations. 3 and more characters will perform fuzzy matching. The search string can be a location name or a postal code. |
count |
Integer | No | 10 |
The number of search results to return. Up to 100 results can be retrieved. |
Sample Request & Response
https://geocoding-api.open-meteo.com/v1/search?name=seat&count=2
{
"results": [
{
"id": 5809844,
"name": "Seattle",
"latitude": 47.60621,
"longitude": -122.33207,
"country": "United States",
"admin1": "Washington",
"admin2": "King",
"admin3": "City of Seattle"
},
{
"id": 2638277,
"name": "Seaton",
"latitude": 52.57489,
"longitude": -0.66759,
"country": "United Kingdom",
"admin1": "England",
"admin3": "Seaton"
}
],
}Refer to Geocoding API Docs for more details.
Current Weather
GET https://api.open-meteo.com/v1/forecast accepts a geographical coordinate, a list of weather variables. URL parameters are listed below:
| Parameter | Format | Required | Default | Description |
|---|---|---|---|---|
latitude, longitude |
Floating point | Yes | - | Geographical WGS84 coordinates of the location. |
current |
String array | No | - | A list of weather variables to get current conditions. |
If weather variables are included in the current array, the response will return the corresponding information:
| Variable | Valid Time | Unit | Description |
|---|---|---|---|
temperature_2m |
Instant | °C (°F) | Air temperature at 2 meters above ground. |
weather_code |
Instant | WMO code | Weather condition as a numeric code. See table below for interpretation. |
Sample Request & Response: https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=temperature_2m,weather_code&temperature_unit=fahrenheit
{
"latitude": 52.52,
"longitude": 13.419998,
"current_units": {
"temperature_2m": "°F",
},
"current": {
"temperature_2m": 35.7,
"weather_code": 0,
}
}Weather Codes
| Code | Summary | Emoji |
|---|---|---|
| 0 | Clear sky | ☀️ |
| 1, 2, 3 | Partly cloudy | 🌤️ |
| 45, 48 | Foggy | 🌫️ |
| 51, 53, 55 | Light drizzle | 🌦️ |
| 56, 57 | Freezing drizzle | 🌧️ |
| 61, 63, 65 | Rainy | 🌧️ |
| 66, 67 | Freezing rain | 🌧️ |
| 71, 73, 75 | Snowfall | ❄️ |
| 77 | Snow grains | ❄️ |
| 80, 81, 82 | Rain showers | 🌦️ |
| 85, 86 | Snow showers | 🌨️ |
| 95 | Thunderstorm | ⛈️ |
| 96, 99 | Severe storm | ⛈️ |
Refer to Forecast API Docs for full details.