Geolocation Assignment- 2
Basic Questions
- Write a program that prints the user’s latitude and longitude in the console.
- Create a button “Get Location” that fetches and displays coordinates when clicked.
- Write code that shows “Location Not Available” if geolocation fails.
- Implement getCurrentPosition() with { enableHighAccuracy: true } and log accuracy.
- Show latitude/longitude on the webpage instead of console.
- Write code to alert the user if location permission is denied.
- Build a function that shows position coordinates plus timestamp.
- Display accuracy (in meters) of current position in the console.
- Create a function that alerts “Tracking started” when watchPosition begins.
- Log coordinates continuously using watchPosition() every update.
- Implement a button “Stop Tracking” that clears watchPosition().
- Write code to display speed (m/s) if available from coords.speed.
- Create a function that logs altitude if available, otherwise log “Altitude unavailable”.
- Build code that displays user’s heading/direction if coords.heading is available.
- Write a snippet that checks if geolocation is supported in the browser or not.
- Implement a button that starts live tracking and shows coordinates updating in real-time.
- Write code that triggers an alert when accuracy is greater than 100 meters.
- Create a program that shows coordinates only once, then automatically stops.
- Build a function that saves the latest latitude and longitude to localStorage.
- Write code that loads saved coordinates from localStorage and displays them.
Intermediate
- Write a program that logs latitude and longitude every 10 seconds using setInterval.
- Implement timeout: show an error if location retrieval takes more than 5 seconds.
- Allow cached location up to 5 minutes old using maximumAge.
- Write a snippet that displays “Fetching location…” until coordinates are retrieved.
- Implement a program that logs all 4 error codes (1–3) with custom messages.
- Build a tracker that calculates distance traveled by the user (use Haversine).
- Create a live speedometer app using coords.speed.
- Write code that stores every location update in an array.
- Build a function that displays last 5 locations stored in the array.
- Implement resume and stop buttons for live tracking using watchPosition().
- Show accuracy of current location in a colored badge (green if <50m, red if >100m).
- Write code that draws user’s location as a marker on Google Maps.
- Build a program that moves the marker on Google Maps as location updates.
- Store user’s movement path as polyline on Google Maps.
- Implement a button “Clear Path” that removes the polyline from the map.
- Create a function that alerts “Low Accuracy” when accuracy > 200 meters.
- Write code that pauses tracking when “Pause” button is clicked and resumes on “Resume”.
- Build a simple attendance system: log “Present” if user shares location within 100m of office coordinates.
- Write code that saves all positions with timestamp in localStorage.
- Display saved positions history as a table on the webpage.
Advanced
- Build a full tracker app: live tracking + saving history in localStorage + rendering table of past positions.
- Implement geolocation with Google Maps where marker auto-updates every 10s.
- Write code to calculate distance between current location and a fixed point using Haversine.
- Trigger an alert if user moves more than 500m from their initial location.
- Build a tracker that calculates average speed after every 1 minute.
- Implement an app that draws a circle of 200m radius around the user on Google Maps.
- Write code to detect when user exits the 200m circle and alert “You left the zone”.
- Build a delivery tracker simulation: marker moves on Google Maps every 5s with random coords.
- Create a live dashboard showing user’s current speed, distance traveled, and total stops.
- Build a complete delivery tracking system using watchPosition() + Google Maps:
-
- Live marker update
- Distance traveled
- History stored in localStorage
- Stop/Resume controls