updated location

This commit is contained in:
Stanimir Karoserov
2014-05-16 16:46:21 +03:00
parent 599bc7c10e
commit 000530e4e8
5 changed files with 151 additions and 35 deletions

View File

@ -125,13 +125,7 @@
<DependentUpon>image-source.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="image-source\index.ts" />
<TypeScriptCompile Include="location\location.android.ts">
<DependentUpon>location.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="location\location.d.ts" />
<TypeScriptCompile Include="location\location.ios.ts">
<DependentUpon>location.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="Tests\file-system-tests.ts" />
<TypeScriptCompile Include="Tests\http-tests.ts" />
<TypeScriptCompile Include="Tests\image-tests.ts" />
@ -198,9 +192,20 @@
<DependentUpon>local-settings.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="local-settings\local-settings-common.ts" />
<TypeScriptCompile Include="location\location-common.ts" />
<TypeScriptCompile Include="location\location-types.ts" />
<TypeScriptCompile Include="Tests\timer-tests.ts" />
<TypeScriptCompile Include="location\location-types.ts">
<DependentUpon>location.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="location\location-manager.android.ts">
<DependentUpon>location-manager.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="location\location-manager.d.ts" />
<TypeScriptCompile Include="location\location-manager.ios.ts">
<DependentUpon>location-manager.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="location\location.impl.ts">
<DependentUpon>location.d.ts</DependentUpon>
</TypeScriptCompile>
<Content Include="_references.ts" />
</ItemGroup>
<ItemGroup>

View File

@ -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

99
location/location-manager.d.ts vendored Normal file
View File

@ -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;
}

View File

@ -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 {

View File

@ -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<types.Location> {
// 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<types.Location> {
var d = promises.defer<types.Location>();
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<t
return d.promise();
}
export class LocationManager {
private nativeManager: locationManagerModule.LocationManager;
public static isEnabled(): boolean {
return locationManagerModule.LocationManager.isEnabled();
}
public static distance(loc1: types.Location, loc2: types.Location): number {
return locationManagerModule.LocationManager.distance(loc1, loc2);
}
constructor() {
this.nativeManager = new locationManagerModule.LocationManager();
}
// monitoring
public startLocationMonitoring(onLocation: (location: types.Location) => 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;
}
}