Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 791 Bytes

useGeoPosition.md

File metadata and controls

37 lines (28 loc) · 791 Bytes

useGeoPosition

Hook that tracks user geographic location

Usage

import { useGeoPosition } from 'use-haki';

const App = () => {
  const { position, isResolved } = useGeoPosition();

  return (
    <section>
      <h1>My position:</h1>
      {isResolved && <p>longitude: {position.cords.longitude}</p>}
      {isResolved && <p>latitude: {position.cords.latitude}</p>}
      {isResolved && <p>latitude: {position.cords.timestamp}</p>}
    </section>
  );
};

Reference

const { isResolved, position } = useGeoPosition();

Returns

  • isLoading
  • isResolved
  • isRejected
  • status
  • error
  • position - gives GeolocationPosition interface with cords and timestamp