Compare commits
2 Commits
51bb5b3833
...
506b15cd4f
Author | SHA1 | Date | |
---|---|---|---|
|
506b15cd4f | ||
|
4a0474546c |
@ -59,10 +59,12 @@ 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;
|
||||||
|
if(p) {
|
||||||
this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude]));
|
this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude]));
|
||||||
this.locationTolerance = p.coords.accuracy;
|
this.locationTolerance = p.coords.accuracy;
|
||||||
this.recalcLocationTolerance();
|
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)";
|
||||||
}
|
}
|
||||||
|
@ -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,23 +9,15 @@ 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.
|
|
||||||
*
|
|
||||||
* @return An observable of Position
|
|
||||||
*/
|
|
||||||
getCurrentPosition(): Observable<Position> {
|
|
||||||
return Observable.create((observer: Observer<Position>) => {
|
|
||||||
// Invokes getCurrentPosition method of Geolocation API.
|
|
||||||
navigator.geolocation.watchPosition(
|
navigator.geolocation.watchPosition(
|
||||||
(position: Position) => {
|
(position: Position) => {
|
||||||
observer.next(position);
|
this.positionObserver$.next(position);
|
||||||
},
|
},
|
||||||
(error: PositionError) => {
|
(error: PositionError) => {
|
||||||
console.debug('Geolocation service: ' + error.message);
|
console.debug('Geolocation service: ' + error.message);
|
||||||
//observer.error(error);
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enableHighAccuracy: true,
|
enableHighAccuracy: true,
|
||||||
@ -33,7 +25,10 @@ export class GeolocationService {
|
|||||||
maximumAge: 0
|
maximumAge: 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getCurrentPosition(): Observable<Position> {
|
||||||
|
return this.positionObserver$;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user