1.0.3 • Published 3 years ago
cadmv-use-geolocation v1.0.3
cadmv-use-geolocation
custom react hook for getting geolocation
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.