# react-hooks-geolocation

> react-hooks-geolocation is React hooks which allows you to handle geolocation API easily with less code.

Latest version **0.1.0** (published 2022-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-hooks-geolocation
pnpm add react-hooks-geolocation
yarn add react-hooks-geolocation
bun add react-hooks-geolocation
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-04-16 |
| First published | 2022-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 31.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | HideBa |
| Maintainers | darwin-education |

## Links

- npm: https://www.npmjs.com/package/react-hooks-geolocation
- npm.io page: https://npm.io/package/react-hooks-geolocation

## Recent versions

- 0.1.0 (latest) — 2022-04-16

## README

# react-hooks-geolocation
react-hooks-geolocation is React hooks which allows you to handle geolocation API easily with less code.

# Getting Started
Install:

```
npm install react react-hooks-geolocation
# or
yarn add react react-hooks-geolocation
```

# Usage
```
import useGeolocation from "react-hooks-geolocation";

  const {location,loading,metaInfo, activate, update, watch, unwatch} = useGeolocation({defaultActive: false, (loc, meta) => {console.log(loc, meta)});

  //Watch geolocation
  const handleWatchLocation = () => {
    watch();
  };

  //Release event handler of watching geolocation
  const handleUnwatchLocation = () => {
    unwatch();
  };

  //Get controll of activation
  const activateGeolocation = () => {
    activate();
  };

  //Update geolocation whenever you want
  const handleUpdateGeolocation = () => {
    update();
  }

  return(
    <div>
      {
        loading ? "loading" : {location.latitude}
      }
    </div>
  )
```

Type
```

export type Location = {
  latitude: number;
  longitude: number;
  altitude: number | null;
};

export type MetaInfo = {
  altitudeAccuracy: number | null;
  accuracy: number | null;
  heading: number | null;
  speed: number | null;
};


export type ErrType =
  | 'PERMISSION_DENIED'
  | 'POSITION_UNAVAILABLE'
  | 'TIMEOUT'
  | 'OTHER';

export type Err = {
  type: ErrType;
  message: string;
};

export type Args = {
  defaultActive?: boolean;
  onGeolocationChange?: (location?: Location, metaInfo?: MetaInfo) => void;
  geolocation?: Geolocation;
};

```

# License
[MIT License](./LICENSE)

---
_Source: https://npm.io/package/react-hooks-geolocation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
