detail + position modifiche

This commit is contained in:
tito
2023-04-15 12:30:52 +02:00
parent d61e6b7a87
commit 4ccb2d5075
3 changed files with 16 additions and 2 deletions

View File

@@ -12,7 +12,7 @@
allowfullscreen> allowfullscreen>
</iframe> </iframe>
</div> </div>
<button (click)="generateQRCode()"> <button>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="17.334" height="23.4863"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="17.334" height="23.4863">
<g> <g>
<rect height="23.4863" opacity="0" width="17.334" x="0" y="0"/> <rect height="23.4863" opacity="0" width="17.334" x="0" y="0"/>

View File

@@ -38,6 +38,7 @@ export class DetailComponent implements OnInit {
console.log(this.id); console.log(this.id);
console.log(this.embed); console.log(this.embed);
this.cord = await this.positionService.getLocation(); this.cord = await this.positionService.getLocation();
console.log(this.cord);
this.checkDistanceTimer(); this.checkDistanceTimer();
} }

View File

@@ -7,7 +7,7 @@ import{Cord} from "../interface/cord";
export class positionService{ export class positionService{
cord: Cord = { lat: 0, lon: 0 }; cord: Cord = { lat: 0, lon: 0 };
getDistanceBetweenCoordinates(lat1: number | undefined, lon1: number | undefined, lat2: number, lon2: number) { /*getDistanceBetweenCoordinates(lat1: number | undefined, lon1: number | undefined, lat2: number, lon2: 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;
@@ -24,8 +24,21 @@ export class positionService{
// Distance in km // Distance in km
return earthRadius * c; return earthRadius * c;
} }
}*/
getDistanceBetweenCoordinates(lat1: number, lon1: number, lat2: number, lon2: number) {
const earthRadius = 6371; // Raggio della Terra in km
const dLat = this.deg2rad(lat2 - lat1);
const dLon = this.deg2rad(lon2 - lon1);
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const distance = earthRadius * c; // Distanza in km
return distance;
} }
deg2rad(deg: number) { deg2rad(deg: number) {
return deg * (Math.PI / 180) return deg * (Math.PI / 180)
} }