fix
This commit is contained in:
@@ -1,2 +1 @@
|
|||||||
</nav>
|
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {interval} from "rxjs";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-detail',
|
selector: 'app-detail',
|
||||||
templateUrl: './detail.component.html',
|
templateUrl: './detail.component.html',
|
||||||
styleUrls: ['./detail.component.css']
|
styleUrls: ['./detail.component.css']
|
||||||
})
|
})
|
||||||
export class DetailComponent implements OnInit{
|
export class DetailComponent implements OnInit {
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.getLocation();
|
this.getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
test = {
|
test = {
|
||||||
name: 'SPAI',
|
name: 'SPAI',
|
||||||
cordinates: "46.165262,8.791225",
|
cordinates: "46.165262,8.791225",
|
||||||
@@ -24,6 +24,7 @@ export class DetailComponent implements OnInit{
|
|||||||
|
|
||||||
showNav = true;
|
showNav = true;
|
||||||
distance = 0;
|
distance = 0;
|
||||||
|
|
||||||
getLocation() {
|
getLocation() {
|
||||||
console.log("get location");
|
console.log("get location");
|
||||||
if (navigator.geolocation) {
|
if (navigator.geolocation) {
|
||||||
@@ -33,7 +34,7 @@ export class DetailComponent implements OnInit{
|
|||||||
console.log(this.cord);
|
console.log(this.cord);
|
||||||
this.checkDistanceTimer();
|
this.checkDistanceTimer();
|
||||||
})
|
})
|
||||||
}else {
|
} else {
|
||||||
alert("Geolocation is not supported by this browser.");
|
alert("Geolocation is not supported by this browser.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,17 +46,17 @@ export class DetailComponent implements OnInit{
|
|||||||
let lat2 = this.test.cordinates.split(",")[0];
|
let lat2 = this.test.cordinates.split(",")[0];
|
||||||
let lon2 = this.test.cordinates.split(",")[1];
|
let lon2 = this.test.cordinates.split(",")[1];
|
||||||
let intervalID = setInterval(() => {
|
let intervalID = setInterval(() => {
|
||||||
if(this.showNav){
|
if (this.showNav) {
|
||||||
this.distance = this.getDistanceBetweenCoordinates(lat1, lon1, +lat2, +lon2);
|
this.distance = this.getDistanceBetweenCoordinates(lat1, lon1, +lat2, +lon2);
|
||||||
console.log(this.distance);
|
console.log(this.distance);
|
||||||
if(this.distance < 0.05){
|
if (this.distance < 0.05) {
|
||||||
this.showNav = false;
|
this.showNav = false;
|
||||||
clearInterval(intervalID);
|
clearInterval(intervalID);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
clearInterval(intervalID);
|
clearInterval(intervalID);
|
||||||
}
|
}
|
||||||
} , 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDistanceBetweenCoordinates(lat1: number, lon1: number, lat2: number, lon2: number) {
|
getDistanceBetweenCoordinates(lat1: number, lon1: number, lat2: number, lon2: number) {
|
||||||
@@ -63,17 +64,18 @@ export class DetailComponent implements OnInit{
|
|||||||
const dLat = this.deg2rad(lat2 - lat1); // deg2rad below
|
const dLat = this.deg2rad(lat2 - lat1); // deg2rad below
|
||||||
const dLon = this.deg2rad(lon2 - lon1);
|
const dLon = this.deg2rad(lon2 - lon1);
|
||||||
const a =
|
const a =
|
||||||
Math.sin(dLat/2) * Math.sin(dLat/2) +
|
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
||||||
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; // Distance in km
|
// Distance in km
|
||||||
return distance;
|
return earthRadius * c;
|
||||||
}
|
}
|
||||||
|
|
||||||
deg2rad(deg: number) {
|
deg2rad(deg: number) {
|
||||||
return deg * (Math.PI/180)
|
return deg * (Math.PI / 180)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Translate } from '@google-cloud/translate/build/src/v2';
|
//import { Translate } from '@google-cloud/translate/build/src/v2';
|
||||||
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@@ -7,15 +7,15 @@ import { Translate } from '@google-cloud/translate/build/src/v2';
|
|||||||
})
|
})
|
||||||
export class TranslateService {
|
export class TranslateService {
|
||||||
|
|
||||||
private translate: Translate;
|
//private translate: Translate;
|
||||||
|
|
||||||
constructor() {
|
// constructor() {
|
||||||
this.translate = new Translate({projectId: 'Modulo-152'});
|
// this.translate = new Translate({projectId: 'Modulo-152'});
|
||||||
}
|
//}
|
||||||
|
|
||||||
async translateText(text: string, target: string): Promise<string> {
|
//async translateText(text: string, target: string): Promise<string> {
|
||||||
const [translation] = await this.translate.translate(text, target);
|
//const [translation] = await this.translate.translate(text, target);
|
||||||
return translation;
|
//return translation;
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user