yarn add user-location-finder
or
npm i user-location-finder
import getUserLocation from 'user-location-finder';
getUserLocation()
.then(location => {
console.log(`Country: ${location.country}, Town: ${location.town}`);
})
.catch(error => {
console.error('Error fetching location:', error);
});
The user location finder package provides a simple and efficient way to retrieve the user's current location, including the country and town/city, directly from their browser. It utilizes the browser's built-in Geolocation API combined with the BigDataCloud reverse geocoding service to convert geographical coordinates (latitude and longitude) into readable location information.
- Easy to Use - Simple API that allows you to get the user's country and town with a single function call.
- No API Key Required - Uses BigDataCloud's free reverse geocoding service, so no API key is needed for basic usage.
- Real-Time Location - Retrieves the user's location in real-time using the browser's Geolocation API.
- Lightweight - Minimal dependencies, ensuring fast performance and easy integration into any JavaScript or Node.js project.
axios for making HTTP requests to the BigDataCloud API.
MIT