I'm finding this concept a little tricky to grasp.
retrieveLongitudeById(id: number | string) {
return this.getHoles().pipe(
map(holes => holes.find(hole => hole.id === +id).lng)
);
}
I want to access this method from my service and incorporate it into my geolocation component. Any advice on how to do that?
Haversine(): void {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition( x => {
this.myLat = x.coords.latitude;
this.myLng = x.coords.longitude;
this.courseLat = this._mont.getHoleLat();
this.courseLng = this._mont.getHoleLng();
console.log(`longitude: ${ this.courseLat } | latitude: ${ this.courseLng }`);
console.log(`longitude: ${ this.myLat } | latitude: ${ this.myLng }`);
const myCoords: GeoCoord = {
latitude: this.myLat,
longitude: this.myLng
};
const dominos: GeoCoord = {
latitude: this.courseLat,
longitude: this.courseLng
};
this.metres = this._haversine.getDistanceInMeters(myCoords, dominos);
this.yards = this._haversine.getDistanceInYards(myCoords, dominos);
this.kilometres = this._haversine.getDistanceInKilometers(myCoords, dominos);
this.miles = this._haversine.getDistanceInMiles(myCoords, dominos);
this.metres = this.metres.toFixed(2);
this.yards = this.yards.toFixed(2);
this.kilometres = this.kilometres.toFixed(2);
this.miles = this.miles.toFixed(2);
});
}
}
Update
export class Hole {
constructor(public id: number, public name: string, public lat: number, public lng: number) { }
}
const HOLES = [
new Hole(1, 'Hole 1', 1234567, -12345324)
];
I'm trying to retrieve these coordinates!