diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html
index 0a00a7f..05f3d1d 100644
--- a/src/app/home/home.component.html
+++ b/src/app/home/home.component.html
@@ -24,7 +24,7 @@
- {{luogo.nome}}
+ {{luogo.location}}
diff --git a/src/app/interface/data.ts b/src/app/interface/data.ts
index 3bf9b4d..04d2051 100644
--- a/src/app/interface/data.ts
+++ b/src/app/interface/data.ts
@@ -3,6 +3,7 @@ export interface Locations {
region: string;
lat: number;
lon: number;
+ distance?: number;
waypoints?: waypoint[];
}
diff --git a/src/app/list/list.component.ts b/src/app/list/list.component.ts
index 0f7cebe..9b99dc6 100644
--- a/src/app/list/list.component.ts
+++ b/src/app/list/list.component.ts
@@ -3,6 +3,8 @@ import {Locations} from "../interface/data";
import {ReadjsonService} from "../service/readjson.service";
import {Observable} from "rxjs";
import {ActivatedRoute} from "@angular/router";
+import {Cord} from "../interface/cord";
+import {positionService} from "../service/position.service";
@Component({
selector: 'app-list',
@@ -16,25 +18,27 @@ export class ListComponent implements OnInit {
isNear: boolean = true;
+ positionCord: any;
- constructor(private route: ActivatedRoute ,private readjsonService: ReadjsonService) {}
+ distance: number = 0;
- ngOnInit(): void {
+ constructor(private route: ActivatedRoute ,private readjsonService: ReadjsonService, private positionService: positionService) {}
+
+ async ngOnInit() {
this.route.params.subscribe(params => {
this.locationParams = params['location'];
});
-
this.readjsonService.getLocations().subscribe(locations => {
this.locations = locations;
- this.checkDataPopulated();
+ if (this.locationParams != null) {
+ this.readjsonService.getLocation(this.locationParams).subscribe(location => {
+ this.location = location;
+ this.checkDataPopulated();
+ });
+ }
});
-
- if (this.locationParams != null) {
- this.readjsonService.getLocation(this.locationParams).subscribe(location => {
- this.location = location;
- this.checkDataPopulated();
- });
- }
+ this.positionCord = await this.readjsonService.getLocations();
+ this.setDistance();
}
private checkDataPopulated(): void {
@@ -50,5 +54,10 @@ export class ListComponent implements OnInit {
}
}
}
-
+ private setDistance(): void{
+ if (this.location && this.isNear){
+ this.distance = this.positionService.getDistanceBetweenCoordinates(this.location.lat, this.location.lon, this.positionCord.lat, this.positionCord.lon);
+ console.log("Distanza: " + this.distance + " km");
+ }
+ }
}
diff --git a/src/app/service/readjson.service.ts b/src/app/service/readjson.service.ts
index 75d9d9a..b737271 100644
--- a/src/app/service/readjson.service.ts
+++ b/src/app/service/readjson.service.ts
@@ -38,6 +38,7 @@ export class ReadjsonService{
tap(data => console.log("data requested", data))
);
}
+
/*
getWaypoints(location: string, id: number): Observable {
return this.locations.pipe(