🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@mborecki/react-geo

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mborecki/react-geo

Package to use [Geolocation API](https://developer.mozilla.org/pl/docs/Web/API/Geolocation_API) in React application. It is using Context API to minimalize event listeners when you need use geolocation data in many conponents.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@mborecki/react-geo

Package to use Geolocation API in React application. It is using Context API to minimalize event listeners when you need use geolocation data in many conponents.

Instalation

yarn add @mborecki/react-geo

How to use

Higher order component


import {GeoModuleProvider} from '@mborecki/react-geo';

const App = () => {
    return <GeoModuleProvider>
        <MyComponent />
    </GeoModuleProvider>
}

Consumer componenet


import {useGeo} from '@mborecki/react-geo';

const MyComponent = () => {
    const {position, accuracy, error} = useGeo();

    return <div>{JSON.stringify(position)}</div>
}

API

GeoModuleProvider

Provider for context module uses to store data.

Props

All properties equals properties from PositionOptions

useGeo()

Hook for getting geolocation data.

  • position - object with position data - undefined if position is not available
  • position.lat - position's latitude in decimal degrees.
  • position.lng - position's longitude in decimal degrees.
  • accuracy - accuracy of the latitude and longitude properties in meters - undefined if position is not available
  • error - object with module error
  • error.type - GEO_MODULE_ERROR
  • error.originalError - oryginal error from browser (if exists). GeolocationPositionError

GEO_MODULE_ERROR

  • GEO_MODULE_ERROR.UNKNOWN - something went wrong
  • GEO_MODULE_ERROR.NO_GEOLOCATION_API - there is no Geolocation API
  • GEO_MODULE_ERROR.PERMISSION_DENIED - The acquisition of the geolocation information failed because the page didn't have the permission to do it.
  • GEO_MODULE_ERROR.POSITION_UNAVAILABLE - The acquisition of the geolocation failed because at least one internal source of position returned an internal error.
  • GEO_MODULE_ERROR.TIMEOUT - The time allowed to acquire the geolocation, defined by PositionOptions.timeout information was reached before the information was obtained.

FAQs

Package last updated on 20 Apr 2021

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