Geolocation Assignment- 2

Basic Questions

  1. Write a program that prints the user’s latitude and longitude in the console.
  2. Create a button “Get Location” that fetches and displays coordinates when clicked.
  3. Write code that shows “Location Not Available” if geolocation fails.
  4. Implement getCurrentPosition() with { enableHighAccuracy: true } and log accuracy.
  5. Show latitude/longitude on the webpage instead of console.
  6. Write code to alert the user if location permission is denied.
  7. Build a function that shows position coordinates plus timestamp.
  8. Display accuracy (in meters) of current position in the console.
  9. Create a function that alerts “Tracking started” when watchPosition begins.
  10. Log coordinates continuously using watchPosition() every update.
  11. Implement a button “Stop Tracking” that clears watchPosition().
  12. Write code to display speed (m/s) if available from coords.speed.
  13. Create a function that logs altitude if available, otherwise log “Altitude unavailable”.
  14. Build code that displays user’s heading/direction if coords.heading is available.
  15. Write a snippet that checks if geolocation is supported in the browser or not.
  16. Implement a button that starts live tracking and shows coordinates updating in real-time.
  17. Write code that triggers an alert when accuracy is greater than 100 meters.
  18. Create a program that shows coordinates only once, then automatically stops.
  19. Build a function that saves the latest latitude and longitude to localStorage.
  20. Write code that loads saved coordinates from localStorage and displays them.

Intermediate

  1. Write a program that logs latitude and longitude every 10 seconds using setInterval.
  2. Implement timeout: show an error if location retrieval takes more than 5 seconds.
  3. Allow cached location up to 5 minutes old using maximumAge.
  4. Write a snippet that displays “Fetching location…” until coordinates are retrieved.
  5. Implement a program that logs all 4 error codes (1–3) with custom messages.
  6. Build a tracker that calculates distance traveled by the user (use Haversine).
  7. Create a live speedometer app using coords.speed.
  8. Write code that stores every location update in an array.
  9. Build a function that displays last 5 locations stored in the array.
  10. Implement resume and stop buttons for live tracking using watchPosition().
  11. Show accuracy of current location in a colored badge (green if <50m, red if >100m).
  12. Write code that draws user’s location as a marker on Google Maps.
  13. Build a program that moves the marker on Google Maps as location updates.
  14. Store user’s movement path as polyline on Google Maps.
  15. Implement a button “Clear Path” that removes the polyline from the map.
  16. Create a function that alerts “Low Accuracy” when accuracy > 200 meters.
  17. Write code that pauses tracking when “Pause” button is clicked and resumes on “Resume”.
  18. Build a simple attendance system: log “Present” if user shares location within 100m of office coordinates.
  19. Write code that saves all positions with timestamp in localStorage.
  20. Display saved positions history as a table on the webpage.

Advanced

  1. Build a full tracker app: live tracking + saving history in localStorage + rendering table of past positions.
  2. Implement geolocation with Google Maps where marker auto-updates every 10s.
  3. Write code to calculate distance between current location and a fixed point using Haversine.
  4. Trigger an alert if user moves more than 500m from their initial location.
  5. Build a tracker that calculates average speed after every 1 minute.
  6. Implement an app that draws a circle of 200m radius around the user on Google Maps.
  7. Write code to detect when user exits the 200m circle and alert “You left the zone”.
  8. Build a delivery tracker simulation: marker moves on Google Maps every 5s with random coords.
  9. Create a live dashboard showing user’s current speed, distance traveled, and total stops.
  10. Build a complete delivery tracking system using watchPosition() + Google Maps:
    • Live marker update
    • Distance traveled
    • History stored in localStorage
    • Stop/Resume controls