geo-location-hook

1.0.6 • Public • Published

GeolocateMe

A ReactJS hook to get the geo-location of the users.

🫶 Support

Liked it? You can show your support with a STAR(⭐).

🔧 Features:

  1. Retrieves the user's current coordinates (latitude and longitude) using the Geolocation API.
  2. Handles cases where geolocation is not supported or the user denies permission.
  3. Returns a state object with loading status , coordinates and error, making it easy to manage location data in your components.

How to use it?

You can use the project in this way:

Install

# with npm
npm install geo-location-hook

# with yarn
yarn add geo-location-hook

Usage

import React from 'react';
import {useGeoLocation} from 'geo-location-hook';

const MyComponent = () => {
  const { loading, coordinates, error } = useGeoLocation();

  if (!loading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return (
    <div>
      Latitude: {coordinates.latitude}, Longitude: {coordinates.longitude}
    </div>
  );
};

export default MyComponent;

Package Sidebar

Install

npm i geo-location-hook

Weekly Downloads

8

Version

1.0.6

License

ISC

Unpacked Size

4.53 kB

Total Files

3

Last publish

Collaborators

  • imrajput