Socket
Book a DemoInstallSign in
Socket

react-hooks-geolocation

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-geolocation

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

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 16 Apr 2022

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