react-use-geolocation
React hook for accessing geolocation.
Installation
Using npm:
$ npm install --save react-use-geolocation
Using yarn:
$ yarn add react-use-geolocation
Since this module uses React's new Hooks feature,
to try this out you'll need to install the 16.8.0
version
of react
and react-dom
:
$ yarn add react@^16.8.0 react-dom@^16.8.0
Usage
;; { const position error = ; if !position && !error return <p>Waiting...</p>; if error return <p>errormessage</p>; return <div> <p> Latitude: positioncoordslatitude </p> <p> Longitude: positioncoordslongitude </p> </div> ;}
API
; : ?Position ?PositionError
Identical to getCurrentPosition
.
Receives an optional PositionOptions
and returns a tuple with the position
and the error.
; : ?Position ?PositionError
Same API as useCurrentPosition
, but watches the location and
updates the component when the location changes.
Contributing
Please feel free to submit any issues or pull requests.
License
MIT