import { Injectable } from '@angular/core'; import { Observer, Observable } from 'rxjs'; @Injectable() export class DeviceOrientationService { /** * Tries HTML5 geolocation. * * Wraps the Geolocation API into an observable. * * @return An observable of Bearing */ getCurrentBearing(): Observable { return Observable.create((observer: Observer) => { let sensor = new Magnetometer(); sensor.onreading= (ev:Event) => { observer.next(Math.atan2(sensor.y, sensor.x) * (180 / Math.PI)); }; }); } }