Compare commits
No commits in common. "506b15cd4fd96aae08d23dced672e3afb1ef2aed" and "51bb5b38332f749c0a46a2f66be065e7dfa66712" have entirely different histories.
506b15cd4f
...
51bb5b3833
@ -59,11 +59,9 @@ export class GpsLocation implements OnInit,OnChanges{
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes.position && this.instance) {
|
||||
var p = changes.position.currentValue as Position;
|
||||
if(p) {
|
||||
this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude]));
|
||||
this.locationTolerance = p.coords.accuracy;
|
||||
this.recalcLocationTolerance();
|
||||
}
|
||||
this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude]));
|
||||
this.locationTolerance = p.coords.accuracy;
|
||||
this.recalcLocationTolerance();
|
||||
}
|
||||
if(changes.heading && this.instance) {
|
||||
this.rotate = "rotate(" + Math.round(changes.heading.currentValue) + " 500 500)";
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observer, Observable,BehaviorSubject } from 'rxjs';
|
||||
import { Observer, Observable } from 'rxjs';
|
||||
|
||||
/**
|
||||
* GeolocationService class.
|
||||
@ -9,26 +9,31 @@ import { Observer, Observable,BehaviorSubject } from 'rxjs';
|
||||
@Injectable()
|
||||
export class GeolocationService {
|
||||
|
||||
private positionObserver$:BehaviorSubject<Position> = new BehaviorSubject<Position>(null);
|
||||
|
||||
constructor() {
|
||||
navigator.geolocation.watchPosition(
|
||||
(position: Position) => {
|
||||
this.positionObserver$.next(position);
|
||||
},
|
||||
(error: PositionError) => {
|
||||
console.debug('Geolocation service: ' + error.message);
|
||||
},
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
timeout: 5000,
|
||||
maximumAge: 0
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries HTML5 geolocation.
|
||||
*
|
||||
* Wraps the Geolocation API into an observable.
|
||||
*
|
||||
* @return An observable of Position
|
||||
*/
|
||||
getCurrentPosition(): Observable<Position> {
|
||||
return this.positionObserver$;
|
||||
return Observable.create((observer: Observer<Position>) => {
|
||||
// Invokes getCurrentPosition method of Geolocation API.
|
||||
navigator.geolocation.watchPosition(
|
||||
(position: Position) => {
|
||||
observer.next(position);
|
||||
},
|
||||
(error: PositionError) => {
|
||||
console.debug('Geolocation service: ' + error.message);
|
||||
//observer.error(error);
|
||||
},
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
timeout: 5000,
|
||||
maximumAge: 0
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user