Peter Bastiani 84a1a04b19
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
AW-6046 Angular improvement
2024-04-15 10:29:47 +02:00

35 lines
928 B
TypeScript

import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
/**
* GeolocationService class.
* https://developers.google.com/maps/documentation/javascript/
* https://dev.w3.org/geo/api/spec-source.html
*/
@Injectable()
export class GeolocationService {
private positionObserver$:BehaviorSubject<GeolocationPosition> = new BehaviorSubject<GeolocationPosition>(null);
constructor() {
navigator.geolocation.watchPosition(
(position: GeolocationPosition) => {
this.positionObserver$.next(position);
},
(error: GeolocationPositionError) => {
console.debug('Geolocation service: ' + error.message);
},
{
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
}
);
}
getCurrentPosition(): Observable<GeolocationPosition> {
return this.positionObserver$;
}
}