my-geo-utils
v1.0.2
Published
A lightweight Node.js library to calculate distance and travel time between coordinates.
Maintainers
Readme
🌍 my-geo-utils
A lightweight Node.js utility library for calculating the distance between two coordinates using the Haversine formula. Includes an estimated travel time based on average speed.
🚀 Features
- Calculate distance (in kilometers) between two latitude/longitude points
- Estimate travel time based on average speed (e.g., by car, bike, etc.)
- Simple and lightweight
📦 Installation
# Local installation for your own project
npm i my-geo-utils📥 Integration
const { getTravelEstimate } = require("my-geo-utils");
const { getDistance } = require("my-geo-utils");
// Example: Phnom Penh to Bangkok
const result = getTravelEstimate(11.5564, 104.9282, 13.7563, 100.5018, 60);
const distance = getDistance(11.5564, 104.9282, 13.7563, 100.5018);
console.log(`🧭 Distance: ${distance} km`);
console.log(
`🚗 Estimated Time: ${result.estimatedTime} (at ${result.averageSpeed} km/h)`
);🖨️ Output:
🧭 Distance: 584.56 km
🕒 Estimated Time: 9 hours, 44 minutes (at 60 km/h)🧠 Function Signature
getTravelEstimate(
lat1: number,
lon1: number,
lat2: number,
lon2: number,
averageSpeedKmH: number = 60
): {
distanceKm: string,
estimatedTime: string,
averageSpeed: number
}🚦 Speed Examples
- Walking: 5 km/h
- Cycling: 15 km/h
- Car: 60 km/h
- Highway: 100 km/h
- Airplane: 800 km/h
