diff --git a/BCL.csproj b/BCL.csproj index 6d92cd7ed..3ba8687c5 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -125,13 +125,7 @@ image-source.d.ts - - location.d.ts - - - location.d.ts - @@ -198,9 +192,20 @@ local-settings.d.ts - - + + location.d.ts + + + location-manager.d.ts + + + + location-manager.d.ts + + + location.d.ts + diff --git a/location/location.android.ts b/location/location-manager.android.ts similarity index 96% rename from location/location.android.ts rename to location/location-manager.android.ts index 3a9a3cd70..c0a84f741 100644 --- a/location/location.android.ts +++ b/location/location-manager.android.ts @@ -1,12 +1,5 @@ import types = require("location/location-types"); import appModule = require("application/application"); -import common = require("location/location-common"); -import merger = require("utils/module-merge"); - -// merge the exports of the types module with the exports of this file -declare var exports; -merger.merge(types, exports); -merger.merge(common, exports); export class LocationManager { // in meters diff --git a/location/location-manager.d.ts b/location/location-manager.d.ts new file mode 100644 index 000000000..8ba682bd3 --- /dev/null +++ b/location/location-manager.d.ts @@ -0,0 +1,99 @@ + +export declare class Location { + latitude: number; + longitude: number; + + altitude: number; // in meters + + horizontalAccuracy: number; // in meters + verticalAccuracy: number; // in meters + + speed: number; // in m/s + + direction: number; // in degrees + + timestamp: Date; + + public android: any; // android Location + public ios: any; // iOS CLLocation +} + +export interface Options { + /** + * Specifies desired accuracy in meters. Defaults to DesiredAccuracy.HIGH + */ + desiredAccuracy?: number; + + /** + * Update distance filter in meters. Specifies how often to update. Default on iOS is no filter, on Android it is 0 meters + */ + updateDistance?: number; + + /** + * Minimum time interval between location updates, in milliseconds (ignored on iOS) + */ + minimumUpdateTime?: number; + + /** + * how old locations to receive in ms. + */ + maximumAge?: number; + + /** + * how long to wait for a location in ms. + */ + timeout?: number; +} + +export declare class LocationManager { + /** + * Report are location services switched ON for this device (on Android) or application (iOS) + */ + static isEnabled(): boolean; + + /** + * Measure distance in meters between two locations + */ + static distance(loc1: Location, loc2: Location): number; + + /** + * Specifies desired accuracy in meters. Defaults to DesiredAccuracy.HIGH + */ + desiredAccuracy: number; + + /** + * Update distance filter in meters. Specifies how often to update. Default on iOS is no filter, on Android it is 0 meters + */ + updateDistance: number; + + /** + * Minimum time interval between location updates, in milliseconds (ignored on iOS) + */ + minimumUpdateTime: number; + + /** + * True if location listener is already started. In this case all other start requests will be ignored + */ + isStarted: boolean; + + // monitoring + + /** + * Starts location monitoring. + */ + startLocationMonitoring(onLocation: (location: Location) => any, onError?: (error: Error) => any, options?: Options); + + /** + * Stops location monitoring + */ + stopLocationMonitoring(); + + // other + + /** + * Returns last known location from device's location services or null of no known last location + */ + lastKnownLocation: Location; +} + + diff --git a/location/location.ios.ts b/location/location-manager.ios.ts similarity index 96% rename from location/location.ios.ts rename to location/location-manager.ios.ts index 1925be5d6..dd4c23cd9 100644 --- a/location/location.ios.ts +++ b/location/location-manager.ios.ts @@ -1,11 +1,4 @@ import types = require("location/location-types"); -import common = require("location/location-common"); -import merger = require("utils/module-merge"); - -// merge the exports of the types module with the exports of this file -declare var exports; -merger.merge(types, exports); -merger.merge(common, exports); export class LocationManager { diff --git a/location/location-common.ts b/location/location.impl.ts similarity index 63% rename from location/location-common.ts rename to location/location.impl.ts index ba349a84b..8b8c5d5ef 100644 --- a/location/location-common.ts +++ b/location/location.impl.ts @@ -1,23 +1,18 @@  -/** -The current way of doing things have a limitation. Due to cyclic dependency - -var LocationManager = require("location/location").LocationManager; - -does not work! We need to rework it using image-source and console method of having common code in one class + specific implementations -for different OSes -*/ - -import types = require("location/location-types"); import promises = require("promises/promises"); -import locationModule = require("location/location"); import timer = require("timer/timer"); +import types = require("location/location-types"); +import locationManagerModule = require("location/location-manager"); -export var getLocation = function (options?: types.Options) : promises.Promise { +// merge the exports of the types module with the exports of this file +declare var exports; +require("utils/module-merge").merge(types, exports); + +export var getLocation = function (options?: types.Options): promises.Promise { var d = promises.defer(); var timerId; - var locationManager = new locationModule.LocationManager(); + var locationManager = new locationManagerModule.LocationManager(); if (options && (0 === options.timeout)) { var location = locationManager.lastKnownLocation; @@ -77,3 +72,34 @@ export var getLocation = function (options?: types.Options) : promises.Promise any, onError?: (error: Error) => any, options?: types.Options) { + this.nativeManager.startLocationMonitoring(onLocation, onError, options); + } + + public stopLocationMonitoring() { + this.nativeManager.stopLocationMonitoring(); + } + + // other + + get lastKnownLocation(): types.Location { + return this.nativeManager.lastKnownLocation; + } +}