Skip to content

Commit 211fcc8

Browse files
author
Stanimir Karoserov
committed
minor location fixes and updates
1 parent a46b631 commit 211fcc8

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

location/location-common.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
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+
211
import types = require("location/location-types");
312
import promises = require("promises/promises");
413
import locationModule = require("location/location");

location/location.android.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ export class LocationManager {
9595
var criteria = new android.location.Criteria();
9696
criteria.setAccuracy((this.desiredAccuracy === types.Accuracy.HIGH) ? 1 : 2);
9797
this.locationListener = <any>new android.location.LocationListener({
98-
onLocationChanged: function (location: android.location.Location) {
98+
onLocationChanged: function (location1: android.location.Location) {
9999
if (this._onLocation) {
100-
this._onLocation(LocationManager.locationFromAndroidLocation(location));
100+
var location = LocationManager.locationFromAndroidLocation(location1);
101+
if (this.maximumAge) {
102+
if (location.timestamp.valueOf() + this.maximumAge > new Date().valueOf()) {
103+
this._onLocation(location);
104+
}
105+
}
106+
else {
107+
this._onLocation(location);
108+
}
101109
}
102110
},
103111

@@ -122,6 +130,7 @@ export class LocationManager {
122130

123131
this.locationListener._onLocation = onLocation;
124132
this.locationListener._onError = onError;
133+
this.locationListener.maximumAge = (options && ("number" === typeof options.maximumAge)) ? options.maximumAge : undefined;
125134
try {
126135
this.androidLocationManager.requestLocationUpdates(long(this.minimumUpdateTime), float(this.updateDistance), criteria, this.locationListener, null);
127136
this.isStarted = true;

location/location.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,9 @@ export declare class LocationManager {
112112
lastKnownLocation: Location;
113113
}
114114

115+
/**
116+
* Fires a single shot location search. If you specify timeout in options, location search will fail on timeout.
117+
* If you specify timeout = 0 it just requests the last known location. However if you specify maximumAge and the
118+
* location received is older it won't be received
119+
*/
115120
export declare var getLocation: (options?: Options) => promises.Promise<Location>;

location/location.ios.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export class LocationManager {
8080
setupWithFunctions: function (onLocation, onError) {
8181
this.onLocation = onLocation;
8282
this.onError = onError;
83+
84+
this.maximumAge = (options && ("number" === typeof options.maximumAge)) ? options.maximumAge : undefined;
8385
}
8486

8587
}, {}).implements({
@@ -90,7 +92,15 @@ export class LocationManager {
9092
locationManagerDidUpdateLocations: function (manager, locations) {
9193
//console.log('location received: ' + locations.count());
9294
for (var i = 0; i < locations.count(); i++) {
93-
this.onLocation(LocationManager.locationFromCLLocation(locations.objectAtIndex(i)));
95+
var location = LocationManager.locationFromCLLocation(locations.objectAtIndex(i));
96+
if (this.maximumAge) {
97+
if (location.timestamp.valueOf() + this.maximumAge > new Date().valueOf()) {
98+
this.onLocation(location);
99+
}
100+
}
101+
else {
102+
this.onLocation(location);
103+
}
94104
}
95105
},
96106

0 commit comments

Comments
 (0)