use-geolocation-position

React hook for geolocation.getCurrentPosition and geolocation.watchPosition

Usage no npm install needed!

<script type="module">
  import useGeolocationPosition from 'https://cdn.skypack.dev/use-geolocation-position';
</script>

README

use-geolocation-position

package version package downloads standard-readme compliant package license make a pull request

React hook for geolocation.getCurrentPosition and getCurrentPosition.watchPosition

Table of Contents

Usage

import React from 'react'

import { useCurrentPosition, useWatchPosition } from 'use-geolocation-position'

export default function App () {
  const currentPosition = useCurrentPosition({
    // Default config
    maximumAge: Infinity,
    timeout: 0,
    enableHighAccuracy: true
  })
  const watchedPosition = useWatchPosition({
    // Default config
    maximumAge: Infinity,
    timeout: 0,
    enableHighAccuracy: true
  })

  return (
    <div className='App'>
      <p>{JSON.stringify(currentPosition, null, 2)}</p>
      <p>{JSON.stringify(watchedPosition, null, 2)}</p>
    </div>
  )
}

Install

This project uses node and npm.

$ npm install use-geolocation-position
$ # OR
$ yarn add use-geolocation-position

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT