New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@awesome-cordova-library/geolocation

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@awesome-cordova-library/geolocation

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

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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

Cordova documentation

MDN

Installation

Typescript/JS

npm install @awesome-cordova-library/geolocation

Cordova

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

Capacitor / Ionic

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

Vanilla

Declaration

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

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

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

React

Declaration

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

Usages

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>
  );
}

Keywords

FAQs

Package last updated on 12 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc