A small assignment to build a hunting log web app that captures date and notes from a form, grabs the user's geolocation, fetches sunrise/sunset and current temperature data from the Open-Meteo API, and stores log entries in localStorage. The app displays saved logs using jQuery.
- Collects date and notes via
FormData. - Uses
navigator.geolocation(via a helpergetLocation()that returns aPromise) to obtain latitude and longitude. - Fetches weather data (sunrise, sunset, current temperature) from Open-Meteo using Axios.
- Persists log entries in
localStorageunder the keyhuntingLogsas an array of objects. - Renders saved logs into the page using jQuery.
Replace LAT and LONG with the user's coordinates:
https://api.open-meteo.com/v1/forecast?latitude=LAT&longitude=LONG&daily=sunrise,sunset¤t=temperature_2m&timezone=auto&forecast_days=1&temperature_unit=fahrenheit
Each saved log should be an object with at least the following fields:
{
latitude: <number>,
longitude: <number>,
date: "YYYY-MM-DD", // string from the form
sunriseTime: DATEIME from API,
sunsetTime: DATETIME from API,
notes: "notes from form string",
temperature: <number> // current temperature from API
}- Using jQuery create a submit event for the form.
- On form
submitevent, callevent.preventDefault(). - Create a
FormDatainstance from the form and extractdateandnotes. - Call
getLocation()(which returns aPromise) to obtain{ latitude, longitude }. - Build the Open-Meteo URL from the coordinates and fetch the weather using Axios.
- Read
daily.sunrise[0]anddaily.sunset[0](or the appropriate fields returned by the API) andcurrent_weather/temperature_2mif available.
- Read
- Construct a
logEntryobject matching the shape above (includenotesfrom the form). - Save the entry to
localStorageunder the keyhuntingLogs:- If
huntingLogsexists,JSON.parse()it, push the new entry, thenJSON.stringify()and save. - If not, create a new array containing the entry and save it.
- If
- Call
loadLogs()to refresh the UI.
-
Read the
huntingLogsvalue fromlocalStorage. -
If it exists,
JSON.parse()it into an array. -
If the array is empty, render a friendly "no logs" message.
-
Otherwise, iterate (or map) over the array and build HTML for each log item. Include:
- Date
- Coordinates (latitude/longitude)
- Sunrise and sunset times
- Notes
- Temperature
-
Use jQuery to set the container's HTML
-
Call
loadLogs()once on page load so previously saved logs are shown automatically.