import { useState, useEffect } from 'react';

export const usePositionTracker = () => {
    const [coords, setCoords] = useState({ latitude: 0, longitude: 0 });

    useEffect(() => {
      const locationID = navigator.geolocation.watchPosition(
        ({ coords }) => {
          setCoords(coords);
        },
        (error) => {
          alert(error.message);
          console.log(error);
        },
        { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
      );
      return () => navigator.geolocation.clearWatch(locationID);
    }, []);
    return coords;
  };