@egodigital/egoose
Version:
Helper classes and functions for Node.js 10 or later.
77 lines (76 loc) • 2.6 kB
TypeScript
/**
* This file is part of the @egodigital/egoose distribution.
* Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
*
* @egodigital/egoose is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* @egodigital/egoose is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Options for 'addressToGeoCoordinates()' function.
*/
export interface AddressToGeoCoordinatesOptions {
/**
* The city.
*/
city?: string;
/**
* The street (with house number, if available).
*/
street?: string;
/**
* The zip code.
*/
zipCode?: string;
}
/**
* Geo coordinates.
*/
export interface GeoCoordinates {
/**
* The latitude.
*/
lat: number;
/**
* The longitude.
*/
lng: number;
}
/**
* Tries to detect geo coordinates from address data.
*
* @param {string|AddressToGeoCoordinatesOptions} queryOrOpts The query string or the options.
* @param {boolean} [throwOnError] Throw an exception on error or return (false). Default: (false)
*
* @return {GeoCoordinates|false} The location or (false) if not found.
*/
export declare function addressToGeoCoordinates(queryOrOpts: string | AddressToGeoCoordinatesOptions, throwOnError?: boolean): Promise<GeoCoordinates | false>;
/**
* Calculates the distance between 2 geo points.
*
* @param {number} lat1 The latitude of the first point.
* @param {number} lon1 The longitude of the first point.
* @param {number} lat2 The latitude of the second point.
* @param {number} lon2 The longitude of the second point.
* @param {string} [unit] The custom unit to use.
*
* @return {number} The distance in meters.
*/
export declare function calcDistance(lat1: number, lon1: number, lat2: number, lon2: number, unit?: string): number;
/**
* Calculates a route via a service, like MapBox.
*
* @param {GeoCoordinates} from The start location.
* @param {GeoCoordinates} to The end location.
*
* @return {Promise<contracts.GeoCoordinates[]>} The promise with the route.
*/
export declare function calcRoute(from: GeoCoordinates, to: GeoCoordinates): Promise<GeoCoordinates[]>;