yanix
v1.0.1
Published
Develop a package that provides easy access to geolocation data and services, such as getting the user's location based on IP address or coordinates, calculating distances between locations, etc.
Downloads
130
Readme
Geolocation API
This package provides functionalities to interact with geolocation data in JavaScript.
Installation
You can install the package via npm:
npm install geolocation-api
Usage
Getting User Location
To get the user's location based on their IP address:
const { getUserLocation } = require('geolocation-api');
getUserLocation().then(location => {
console.log('User location:', location);
});
The getUserLocation
function returns an object containing the user's city, country, and coordinates.
Calculating Distance
To calculate the distance between two sets of coordinates:
const { calculateDistance } = require('geolocation-api');
const coord1 = { lat: 40.7128, lon: -74.006 };
const coord2 = { lat: 34.0522, lon: -118.2437 };
const distance = calculateDistance(coord1, coord2);
console.log('Distance:', distance, 'meters');
The calculateDistance
function takes two sets of coordinates (latitude and longitude) as input and returns the distance between them in meters.
License
This project is licensed under the MIT License - see the LICENSE file for details.