28 lines
632 B
TypeScript
28 lines
632 B
TypeScript
|
import { Injectable } from '@nestjs/common';
|
||
|
import { Geodesic as Geolib, GeodesicClass } from 'geographiclib-geodesic';
|
||
|
import { IGeodesic } from '../../domain/interfaces/geodesic.interface';
|
||
|
|
||
|
@Injectable()
|
||
|
export class Geodesic implements IGeodesic {
|
||
|
private geod: GeodesicClass;
|
||
|
|
||
|
constructor() {
|
||
|
this.geod = Geolib.WGS84;
|
||
|
}
|
||
|
|
||
|
inverse = (
|
||
|
lon1: number,
|
||
|
lat1: number,
|
||
|
lon2: number,
|
||
|
lat2: number,
|
||
|
): { azimuth: number; distance: number } => {
|
||
|
const { azi2: azimuth, s12: distance } = this.geod.Inverse(
|
||
|
lat1,
|
||
|
lon1,
|
||
|
lat2,
|
||
|
lon2,
|
||
|
);
|
||
|
return { azimuth, distance };
|
||
|
};
|
||
|
}
|