diff --git a/src/position.ts b/src/position.ts index 9b61878..14f25fb 100644 --- a/src/position.ts +++ b/src/position.ts @@ -57,14 +57,14 @@ export class Position implements IPosition { public distanceTo(other: IPosition): number { const R = 6371e3; // Earth radius in meters - const φ1 = this.latitude * Math.PI / 180; - const φ2 = other.latitude * Math.PI / 180; - const Δφ = (other.latitude - this.latitude) * Math.PI / 180; - const Δλ = (other.longitude - this.longitude) * Math.PI / 180; + const lat1 = this.latitude * Math.PI / 180; + const lat2 = other.latitude * Math.PI / 180; + const dLat = (other.latitude - this.latitude) * Math.PI / 180; + const dLon = (other.longitude - this.longitude) * Math.PI / 180; - const a = Math.sin(Δφ/2) * Math.sin(Δφ/2) + - Math.cos(φ1) * Math.cos(φ2) * - Math.sin(Δλ/2) * Math.sin(Δλ/2); + const a = Math.sin(dLat/2) * Math.sin(dLat/2) + + Math.cos(lat1) * Math.cos(lat2) * + Math.sin(dLon/2) * Math.sin(dLon/2); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); return R * c; // Distance in meters