1.0.1 • Published 3 years ago

@mborecki/react-geo v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@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.
1.0.1

3 years ago

1.0.0

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago