UNPKG

@cdeshpande/geo-utils

Version:

A lightweight, blazing-fast TypeScript library for calculating distances (Haversine) and geospatial math with support for kilometers and miles.

57 lines (50 loc) 2.1 kB
type Unit = 'km' | 'miles'; /** * Calculates the Haversine distance between two coordinates. * @param lat1 Latitude of point 1 * @param lon1 Longitude of point 1 * @param lat2 Latitude of point 2 * @param lon2 Longitude of point 2 * @param unit Unit of measurement: 'km' or 'miles' (default: 'km') * @returns Distance between the two coordinates */ declare function haversineDistance(lat1: number, lon1: number, lat2: number, lon2: number, unit?: Unit): number; /** * Calculates the midpoint between two latitude/longitude coordinates. */ declare function midpoint(lat1: number, lon1: number, lat2: number, lon2: number): { latitude: number; longitude: number; }; /** * Calculates Vincenty distance between two latitude/longitude points. * @param lat1 Latitude of the first point * @param lon1 Longitude of the first point * @param lat2 Latitude of the second point * @param lon2 Longitude of the second point * @returns Distance in meters */ declare function vincentyDistance(lat1: number, lon1: number, lat2: number, lon2: number): number; /** * Calculates the initial bearing (forward azimuth) from point A to point B. * @param lat1 Latitude of the starting point * @param lon1 Longitude of the starting point * @param lat2 Latitude of the destination point * @param lon2 Longitude of the destination point * @returns Initial bearing in degrees (0–360°) */ declare function initialBearing(lat1: number, lon1: number, lat2: number, lon2: number): number; /** * Calculates the destination point given a start point, distance, and bearing. * @param lat Latitude of the start point * @param lon Longitude of the start point * @param distance Distance to travel * @param bearing Bearing in degrees * @param unit Unit of distance ('km' or 'miles') * @returns Coordinates of the destination point */ declare function destinationPoint(lat: number, lon: number, distance: number, bearing: number, unit?: Unit): { latitude: number; longitude: number; }; export { destinationPoint, haversineDistance, initialBearing, midpoint, vincentyDistance };