1.0.8 • Published 4 years ago

react-navigator-geolocation v1.0.8

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

react-navigator-geolocation

A react geolocationing hook

Installation

Yarn

$ yarn add react-navigator-geolocation

Npm

$ npm install react-navigator-geolocation

Examples

Edit distracted-hellman-8ychm
Simple syntax

import React from "react";
import useGeolocation from "react-navigator-geolocation";

const App: React.FC = () => {
  const { isEnabled, coords } = useGeolocation();

  return isEnabled ? (
    <h3>{ coords?.latitude + ', ' + coords?.longitude }</h3>
  ) : (
    <h4>Location permission is not enabled</h4>
  )
};

export default App;

Edit cold-voice-ofn2p
Suppressed on mountage

import React from "react";
import useGeolocation from "react-navigator-geolocation";

const App: React.FC = () => {
  const { isAvailable, isEnabled, coords, suppressRequest } = useGeolocation({ suppressOnMount: true });

  return isAvailable ? (
    isEnabled ? (
      <div>
        <h1>Coordinates granted</h1>
        <h2>{coords?.latitude + ', ' + coords?.longitude}</h2>
      </div>
    ) : isEnabled === false ? (
      <h1>Location permission disabled</h1>
    ) : (
      <button type="button" onClick={() => suppressRequest(false)}>
        disable suppression
      </button>
    )
  ) : (
    <h1>Your browser doesn't support Geolocation API</h1>
  );
};

export default App;

Parameters

ParamTypeDefaultDefinition
suppressOnMountbooleanfalseSuppress request on mountage
positionOptionsobject{ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }Read more
watchModebooleanfalseWhen enable it returns periodically (by movement) coordinates

useGeolocation({ suppressOnMount: false, positionOptions: { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }, watchMode: false })

Response

VariableTypeDefinition
isAvailablebooleanBrowser does support Geolocation API
isSupressedbooleanIf request was suppressed
isEnabledbooleanIf location is granted or denied
isExpiredbooleanIf request is timed out
coordsobjectRead more
suppressRequestmethodIt receives a boolean as value
watchIdnumberIf watchMode is enabled you'll get the id of watching

const { isAvailable, isSupressed, isEnabled, isExpired, coords, suppressRequest, watchId } = useGeolocation(...)

License

MIT

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago