1.0.2 • Published 2 years ago

geo-span-measure v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

geo-span-measure

A simple npm package for calculating distance between two coordinates using the Haversine formula.

Installation

npm install geo-span-measure

Usage

const geo-span-measure = require('geo-span-measure');

const coord1 = [latitude1, longitude1]; // Replace with actual coordinates
const coord2 = [latitude2, longitude2]; // Replace with actual coordinates

// Calculate distance in kilometers (default)
const distanceInKilometers = geo-span-measure(coord1, coord2);
console.log(`Distance in kilometers: ${distanceInKilometers} km`);

// Calculate distance in miles
const distanceInMiles = geo-span-measure(coord1, coord2, 'miles');
console.log(`Distance in miles: ${distanceInMiles} miles`);

// Calculate distance in meters
const distanceInMeters = geo-span-measure(coord1, coord2, 'meters');
console.log(`Distance in meters: ${distanceInMeters} meters`);

Function Explanation

The geo-span-measure function takes two sets of coordinates and an optional unit parameter (defaulting to kilometers if not specified). It uses the Haversine formula to calculate the distance between the two points on the Earth's surface.

Parameters

  • coord1: Array containing the latitude and longitude of the first coordinate.
  • coord2: Array containing the latitude and longitude of the second coordinate.
  • unit: Optional string parameter specifying the desired unit for the output distance ('kilometers', 'miles', or 'meters').

Return Value

The function returns the calculated distance between the two coordinates in the specified unit.

Example

const distanceInKilometers = geo-span-measure([37.7749, -122.4194], [34.0522, -118.2437]);
console.log(`Distance in kilometers: ${distanceInKilometers} km`);

Earth Radius

The function uses the following Earth radius for different units:

  • Kilometers: 6357 km
  • Miles: 3950 miles
  • Meters: 6371000 meters Users can specify the unit according to their preference.

License

This project is licensed under the ISC License - see the LICENSE file for details.

This README includes explanations for the parameters, return value, example usage, a note about distance formatting, and details about Earth radius for different units. Adjustments can be made based on your specific requirements and preferences.

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago