Compare commits

..

2 Commits

Author SHA1 Message Date
Willem Dantuma
506b15cd4f Fix null ref
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
2020-05-19 11:51:06 +02:00
Willem Dantuma
4a0474546c Converted observer to behaviorsubject 2020-05-19 11:46:27 +02:00
2 changed files with 26 additions and 29 deletions

View File

@ -59,9 +59,11 @@ export class GpsLocation implements OnInit,OnChanges{
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if (changes.position && this.instance) { if (changes.position && this.instance) {
var p = changes.position.currentValue as Position; var p = changes.position.currentValue as Position;
this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude])); if(p) {
this.locationTolerance = p.coords.accuracy; this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude]));
this.recalcLocationTolerance(); this.locationTolerance = p.coords.accuracy;
this.recalcLocationTolerance();
}
} }
if(changes.heading && this.instance) { if(changes.heading && this.instance) {
this.rotate = "rotate(" + Math.round(changes.heading.currentValue) + " 500 500)"; this.rotate = "rotate(" + Math.round(changes.heading.currentValue) + " 500 500)";

View File

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observer, Observable } from 'rxjs'; import { Observer, Observable,BehaviorSubject } from 'rxjs';
/** /**
* GeolocationService class. * GeolocationService class.
@ -9,31 +9,26 @@ import { Observer, Observable } from 'rxjs';
@Injectable() @Injectable()
export class GeolocationService { export class GeolocationService {
/** private positionObserver$:BehaviorSubject<Position> = new BehaviorSubject<Position>(null);
* Tries HTML5 geolocation.
* constructor() {
* Wraps the Geolocation API into an observable. navigator.geolocation.watchPosition(
* (position: Position) => {
* @return An observable of Position this.positionObserver$.next(position);
*/ },
getCurrentPosition(): Observable<Position> { (error: PositionError) => {
return Observable.create((observer: Observer<Position>) => { console.debug('Geolocation service: ' + error.message);
// Invokes getCurrentPosition method of Geolocation API. },
navigator.geolocation.watchPosition( {
(position: Position) => { enableHighAccuracy: true,
observer.next(position); timeout: 5000,
}, maximumAge: 0
(error: PositionError) => { }
console.debug('Geolocation service: ' + error.message); );
//observer.error(error);
},
{
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
}
);
});
} }
getCurrentPosition(): Observable<Position> {
return this.positionObserver$;
}
} }