Skip to content

Commit 000530e

Browse files
author
Stanimir Karoserov
committed
updated location
1 parent 599bc7c commit 000530e

5 files changed

Lines changed: 151 additions & 35 deletions

File tree

BCL.csproj

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,7 @@
125125
<DependentUpon>image-source.d.ts</DependentUpon>
126126
</TypeScriptCompile>
127127
<TypeScriptCompile Include="image-source\index.ts" />
128-
<TypeScriptCompile Include="location\location.android.ts">
129-
<DependentUpon>location.d.ts</DependentUpon>
130-
</TypeScriptCompile>
131128
<TypeScriptCompile Include="location\location.d.ts" />
132-
<TypeScriptCompile Include="location\location.ios.ts">
133-
<DependentUpon>location.d.ts</DependentUpon>
134-
</TypeScriptCompile>
135129
<TypeScriptCompile Include="Tests\file-system-tests.ts" />
136130
<TypeScriptCompile Include="Tests\http-tests.ts" />
137131
<TypeScriptCompile Include="Tests\image-tests.ts" />
@@ -198,9 +192,20 @@
198192
<DependentUpon>local-settings.d.ts</DependentUpon>
199193
</TypeScriptCompile>
200194
<TypeScriptCompile Include="local-settings\local-settings-common.ts" />
201-
<TypeScriptCompile Include="location\location-common.ts" />
202-
<TypeScriptCompile Include="location\location-types.ts" />
203195
<TypeScriptCompile Include="Tests\timer-tests.ts" />
196+
<TypeScriptCompile Include="location\location-types.ts">
197+
<DependentUpon>location.d.ts</DependentUpon>
198+
</TypeScriptCompile>
199+
<TypeScriptCompile Include="location\location-manager.android.ts">
200+
<DependentUpon>location-manager.d.ts</DependentUpon>
201+
</TypeScriptCompile>
202+
<TypeScriptCompile Include="location\location-manager.d.ts" />
203+
<TypeScriptCompile Include="location\location-manager.ios.ts">
204+
<DependentUpon>location-manager.d.ts</DependentUpon>
205+
</TypeScriptCompile>
206+
<TypeScriptCompile Include="location\location.impl.ts">
207+
<DependentUpon>location.d.ts</DependentUpon>
208+
</TypeScriptCompile>
204209
<Content Include="_references.ts" />
205210
</ItemGroup>
206211
<ItemGroup>
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import types = require("location/location-types");
22
import appModule = require("application/application");
3-
import common = require("location/location-common");
4-
import merger = require("utils/module-merge");
5-
6-
// merge the exports of the types module with the exports of this file
7-
declare var exports;
8-
merger.merge(types, exports);
9-
merger.merge(common, exports);
103

114
export class LocationManager {
125
// in meters

location/location-manager.d.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
export declare class Location {
3+
latitude: number;
4+
longitude: number;
5+
6+
altitude: number; // in meters
7+
8+
horizontalAccuracy: number; // in meters
9+
verticalAccuracy: number; // in meters
10+
11+
speed: number; // in m/s
12+
13+
direction: number; // in degrees
14+
15+
timestamp: Date;
16+
17+
public android: any; // android Location
18+
public ios: any; // iOS CLLocation
19+
}
20+
21+
export interface Options {
22+
/**
23+
* Specifies desired accuracy in meters. Defaults to DesiredAccuracy.HIGH
24+
*/
25+
desiredAccuracy?: number;
26+
27+
/**
28+
* Update distance filter in meters. Specifies how often to update. Default on iOS is no filter, on Android it is 0 meters
29+
*/
30+
updateDistance?: number;
31+
32+
/**
33+
* Minimum time interval between location updates, in milliseconds (ignored on iOS)
34+
*/
35+
minimumUpdateTime?: number;
36+
37+
/**
38+
* how old locations to receive in ms.
39+
*/
40+
maximumAge?: number;
41+
42+
/**
43+
* how long to wait for a location in ms.
44+
*/
45+
timeout?: number;
46+
}
47+
48+
export declare class LocationManager {
49+
/**
50+
* Report are location services switched ON for this device (on Android) or application (iOS)
51+
*/
52+
static isEnabled(): boolean;
53+
54+
/**
55+
* Measure distance in meters between two locations
56+
*/
57+
static distance(loc1: Location, loc2: Location): number;
58+
59+
/**
60+
* Specifies desired accuracy in meters. Defaults to DesiredAccuracy.HIGH
61+
*/
62+
desiredAccuracy: number;
63+
64+
/**
65+
* Update distance filter in meters. Specifies how often to update. Default on iOS is no filter, on Android it is 0 meters
66+
*/
67+
updateDistance: number;
68+
69+
/**
70+
* Minimum time interval between location updates, in milliseconds (ignored on iOS)
71+
*/
72+
minimumUpdateTime: number;
73+
74+
/**
75+
* True if location listener is already started. In this case all other start requests will be ignored
76+
*/
77+
isStarted: boolean;
78+
79+
// monitoring
80+
81+
/**
82+
* Starts location monitoring.
83+
*/
84+
startLocationMonitoring(onLocation: (location: Location) => any, onError?: (error: Error) => any, options?: Options);
85+
86+
/**
87+
* Stops location monitoring
88+
*/
89+
stopLocationMonitoring();
90+
91+
// other
92+
93+
/**
94+
* Returns last known location from device's location services or null of no known last location
95+
*/
96+
lastKnownLocation: Location;
97+
}
98+
99+
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
import types = require("location/location-types");
2-
import common = require("location/location-common");
3-
import merger = require("utils/module-merge");
4-
5-
// merge the exports of the types module with the exports of this file
6-
declare var exports;
7-
merger.merge(types, exports);
8-
merger.merge(common, exports);
92

103
export class LocationManager {
114

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11

2-
/**
3-
The current way of doing things have a limitation. Due to cyclic dependency
4-
5-
var LocationManager = require("location/location").LocationManager;
6-
7-
does not work! We need to rework it using image-source and console method of having common code in one class + specific implementations
8-
for different OSes
9-
*/
10-
11-
import types = require("location/location-types");
122
import promises = require("promises/promises");
13-
import locationModule = require("location/location");
143
import timer = require("timer/timer");
4+
import types = require("location/location-types");
5+
import locationManagerModule = require("location/location-manager");
6+
7+
// merge the exports of the types module with the exports of this file
8+
declare var exports;
9+
require("utils/module-merge").merge(types, exports);
1510

16-
export var getLocation = function (options?: types.Options) : promises.Promise<types.Location> {
11+
export var getLocation = function (options?: types.Options): promises.Promise<types.Location> {
1712
var d = promises.defer<types.Location>();
1813

1914
var timerId;
20-
var locationManager = new locationModule.LocationManager();
15+
var locationManager = new locationManagerModule.LocationManager();
2116

2217
if (options && (0 === options.timeout)) {
2318
var location = locationManager.lastKnownLocation;
@@ -77,3 +72,34 @@ export var getLocation = function (options?: types.Options) : promises.Promise<t
7772

7873
return d.promise();
7974
}
75+
76+
export class LocationManager {
77+
private nativeManager: locationManagerModule.LocationManager;
78+
79+
public static isEnabled(): boolean {
80+
return locationManagerModule.LocationManager.isEnabled();
81+
}
82+
83+
public static distance(loc1: types.Location, loc2: types.Location): number {
84+
return locationManagerModule.LocationManager.distance(loc1, loc2);
85+
}
86+
87+
constructor() {
88+
this.nativeManager = new locationManagerModule.LocationManager();
89+
}
90+
91+
// monitoring
92+
public startLocationMonitoring(onLocation: (location: types.Location) => any, onError?: (error: Error) => any, options?: types.Options) {
93+
this.nativeManager.startLocationMonitoring(onLocation, onError, options);
94+
}
95+
96+
public stopLocationMonitoring() {
97+
this.nativeManager.stopLocationMonitoring();
98+
}
99+
100+
// other
101+
102+
get lastKnownLocation(): types.Location {
103+
return this.nativeManager.lastKnownLocation;
104+
}
105+
}

0 commit comments

Comments
 (0)