An open API service indexing awesome lists of open source software.

https://github.com/jsoncruz/react-navigator-geolocation

A react geolocation hook
https://github.com/jsoncruz/react-navigator-geolocation

coordinates geolocation hook reactjs

Last synced: 3 months ago
JSON representation

A react geolocation hook

Awesome Lists containing this project

README

          

# react-navigator-geolocation

A react geolocationing hook

## Installation

**Yarn**

```console
$ yarn add react-navigator-geolocation
```

**Npm**

```console
$ npm install react-navigator-geolocation
```

## Examples

[![Edit distracted-hellman-8ychm](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/distracted-hellman-8ychm?fontsize=14&hidenavigation=1&theme=dark)
*Simple syntax*

```TSX
import React from "react";
import useGeolocation from "react-navigator-geolocation";

const App: React.FC = () => {
const { isEnabled, coords } = useGeolocation();

return isEnabled ? (

{ coords?.latitude + ', ' + coords?.longitude }


) : (

Location permission is not enabled


)
};

export default App;

```

[![Edit cold-voice-ofn2p](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/cold-voice-ofn2p?fontsize=14&hidenavigation=1&theme=dark)
*Suppressed on mountage*

```TSX

import React from "react";
import useGeolocation from "react-navigator-geolocation";

const App: React.FC = () => {
const { isAvailable, isEnabled, coords, suppressRequest } = useGeolocation({ suppressOnMount: true });

return isAvailable ? (
isEnabled ? (


Coordinates granted


{coords?.latitude + ', ' + coords?.longitude}



) : isEnabled === false ? (

Location permission disabled


) : (
suppressRequest(false)}>
disable suppression

)
) : (

Your browser doesn't support Geolocation API


);
};

export default App;
```

## Parameters

| Param | Type | Default | Definition |
| :-------------- | :-----: | :-----: | :--------- |
| suppressOnMount | boolean | `false` | Suppress request on mountage |
| positionOptions | object | `{ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }` | [Read more](https://developer.mozilla.org/pt-BR/docs/Web/API/PositionOptions) |
| watchMode | boolean | `false` | When enable it returns periodically (by movement) coordinates |

> useGeolocation({ suppressOnMount: false, positionOptions: { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }, watchMode: false })

## Response

| Variable | Type | Definition |
| :------: | :--: | :--------- |
| isAvailable | boolean | Browser does support Geolocation API |
| isSupressed | boolean | If request was suppressed |
| isEnabled | boolean | If location is granted or denied |
| isExpired | boolean | If request is timed out |
| coords | object | [Read more](https://developer.mozilla.org/pt-BR/docs/Web/API/GeolocationCoordinates)
| suppressRequest | method | It receives a boolean as value |
| watchId | number | If watchMode is enabled you'll get the id of watching

> const { isAvailable, isSupressed, isEnabled, isExpired, coords, suppressRequest, watchId } = useGeolocation(...)

## License
[MIT](https://github.com/dev-judsoncruz/react-navigator-geolocation/blob/master/LICENSE)