fix input on getDistanceBetweenCoordinates
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import{Cord} from "../interface/cord";
|
import {Cord} from "../interface/cord";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -26,7 +26,7 @@ export class positionService{
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
getDistanceBetweenCoordinates(lat1: number | undefined, lon1: number | undefined, lat2: number, lon2: number) {
|
getDistanceBetweenCoordinates(lat1: number | undefined, lon1: number | undefined, lat2: number, lon2: number): number{
|
||||||
if (lat1 === undefined || lon1 === undefined) {
|
if (lat1 === undefined || lon1 === undefined) {
|
||||||
console.log('lat1 or lon1 is undefined')
|
console.log('lat1 or lon1 is undefined')
|
||||||
return 0;
|
return 0;
|
||||||
@@ -38,8 +38,7 @@ export class positionService{
|
|||||||
Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) *
|
Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) *
|
||||||
Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
||||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||||
const distance = earthRadius * c; // Distanza in km
|
return earthRadius * c;
|
||||||
return distance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user