Skip to content

This is a custom hook for getting the geolocation of the user

Notifications You must be signed in to change notification settings

iamrajput/custom-geo-location-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

This is a custom hook for getting the geolocation of the user

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published