# @awesome-cordova-library/geolocation

> This plugin provides information about the device's location, such as latitude and longitude.

Latest version **1.0.1** (published 2023-09-12) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @awesome-cordova-library/geolocation
pnpm add @awesome-cordova-library/geolocation
yarn add @awesome-cordova-library/geolocation
bun add @awesome-cordova-library/geolocation
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-09-12 |
| First published | 2022-10-25 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jordan AZOULAY |
| Maintainers | joazco |
| Keywords | cordova, capacitor, ionic, javascript, mobile, geolocation, location, reactjs |

## Links

- npm: https://www.npmjs.com/package/@awesome-cordova-library/geolocation
- Repository: https://github.com/joazco/awesome-cordova-library
- Issues: https://github.com/joazco/awesome-cordova-library/issues
- npm.io page: https://npm.io/package/@awesome-cordova-library/geolocation

## Recent versions

- 1.0.1 (latest) — 2023-09-12
- 1.0.0 — 2022-10-25

## README

---
id: plugin-geolocation
title: Geolocation
tags:
  - cordova
  - capacitor
  - ionic
  - javascript
  - typescript
  - plugin
  - mobile
  - geolocation
---

# Geolocation

This plugin provides information about the device's location, such as latitude and longitude.

[Online documentation](https://awesomecordovalibrary.com)

[Cordova documentation](https://cordova.apache.org/docs/en/11.x/reference/cordova-plugin-geolocation/index.html)

[MDN](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API)

## Installation

### Typescript/JS

```sh
npm install @awesome-cordova-library/geolocation
```

### Cordova

```sh
cordova plugin add cordova-plugin-geolocation
npm install @awesome-cordova-library/geolocation
```

### Capacitor / Ionic

```bash
npm install cordova-plugin-geolocation
npm install @awesome-cordova-library/geolocation
npx cap sync
```

## Vanilla

### Declaration

```typescript
class Geolocation {
  static getCurrentPosition(
    successCallback: PositionCallback,
    errorCallback?: PositionErrorCallback | null,
    options?: PositionOptions
  ): void;
  static watchPosition(
    successCallback: PositionCallback,
    errorCallback?: PositionErrorCallback | null,
    options?: PositionOptions
  ): number;
  static clearWatch(watchId: number): void;
}
```

### Usages

```typescript
import Geolocation from "@awesome-cordova-library/geolocation";

Geolocation.getCurrentPosition(
  () => {},
  () => {},
  {}
);
const watchid = Geolocation.watchPosition(
  () => {},
  () => {},
  {}
);
Geolocation.clearWatch(watchid);
```

## React

### Declaration

```typescript
const useGeolocation: () => {
  getCurrentPosition: (
    options?: PositionOptions
  ) => Promise<GeolocationPosition>;
  watchPosition: (
    successCallback: PositionCallback,
    errorCallback?: PositionErrorCallback | null,
    options?: PositionOptions
  ) => number;
  clearWatch: (watchId: number) => void;
};
```

### Usages

```typescript
import { useState } from "react";
import useGeolocation from "@awesome-cordova-library/geolocation/lib/react";

function App() {
  const [loading, setLoading] = useState<boolean>(false);
  const [position, setPosition] = useState<GeolocationPosition | undefined>();
  const { getCurrentPosition } = useGeolocation();

  return (
    <div>
      {position && (
        <div>
          <p>
            Latitude: {position.coords.latitude} <br /> Longitude:{" "}
            {position.coords.longitude}
          </p>
        </div>
      )}
      <div>
        <button
          onClick={() => {
            setLoading(true);
            getCurrentPosition()
              .then((p) => {
                setPosition(p);
              })
              .finally(() => {
                setLoading(false);
              });
          }}
        >
          Get current position
        </button>
      </div>
    </div>
  );
}
```

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