1.0.3 • Published 3 years ago

cadmv-use-geolocation v1.0.3

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

cadmv-use-geolocation

custom react hook for getting geolocation

NPM JavaScript Style Guide

Install

npm install --save cadmv-use-geolocation

Usage

import React from 'react'

import { useGeolocation, getDistanceFromLatLonInKm, getDistanceFromLatLonInMiles } from 'cadmv-use-geolocation'

function App() {
  const officeLat = 38.55
  const officeLong = -121.48
  const { latitude, longitude, error } = useGeolocation()
  return (
    <div>
      latitude: {latitude}
      <br />
      longitude: {longitude}
      <br />
      error: {error}
      <br />
      current distance to 2415 1st Street Sacramento CA 95818 in KM: {latitude && longitude ? getDistanceFromLatLonInKm(latitude, longitude, officeLat, officeLong) : `please allow access to your location`}
      <br />
      current distance to 2415 1st Street Sacramento CA 95818 in Miles: {latitude && longitude ? getDistanceFromLatLonInMiles(latitude, longitude, officeLat, officeLong) : `please allow access to your location`}
      <br />
    </div>
  )
}

note: in order to calculate teh distance between two latitude and longitude positions the haversinse formula was utilized.

License

MIT © lauherkdmv


This hook is created using create-react-hook.

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago