minor location fixes and updates

This commit is contained in:
Stanimir Karoserov
2014-05-16 13:48:00 +03:00
parent a46b631812
commit 211fcc8d4e
4 changed files with 36 additions and 3 deletions

View File

@ -1,4 +1,13 @@

/**
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");

View File

@ -95,9 +95,17 @@ export class LocationManager {
var criteria = new android.location.Criteria();
criteria.setAccuracy((this.desiredAccuracy === types.Accuracy.HIGH) ? 1 : 2);
this.locationListener = <any>new android.location.LocationListener({
onLocationChanged: function (location: android.location.Location) {
onLocationChanged: function (location1: android.location.Location) {
if (this._onLocation) {
this._onLocation(LocationManager.locationFromAndroidLocation(location));
var location = LocationManager.locationFromAndroidLocation(location1);
if (this.maximumAge) {
if (location.timestamp.valueOf() + this.maximumAge > new Date().valueOf()) {
this._onLocation(location);
}
}
else {
this._onLocation(location);
}
}
},
@ -122,6 +130,7 @@ export class LocationManager {
this.locationListener._onLocation = onLocation;
this.locationListener._onError = onError;
this.locationListener.maximumAge = (options && ("number" === typeof options.maximumAge)) ? options.maximumAge : undefined;
try {
this.androidLocationManager.requestLocationUpdates(long(this.minimumUpdateTime), float(this.updateDistance), criteria, this.locationListener, null);
this.isStarted = true;

View File

@ -112,4 +112,9 @@ export declare class LocationManager {
lastKnownLocation: Location;
}
/**
* Fires a single shot location search. If you specify timeout in options, location search will fail on timeout.
* If you specify timeout = 0 it just requests the last known location. However if you specify maximumAge and the
* location received is older it won't be received
*/
export declare var getLocation: (options?: Options) => promises.Promise<Location>;

View File

@ -80,6 +80,8 @@ export class LocationManager {
setupWithFunctions: function (onLocation, onError) {
this.onLocation = onLocation;
this.onError = onError;
this.maximumAge = (options && ("number" === typeof options.maximumAge)) ? options.maximumAge : undefined;
}
}, {}).implements({
@ -90,7 +92,15 @@ export class LocationManager {
locationManagerDidUpdateLocations: function (manager, locations) {
//console.log('location received: ' + locations.count());
for (var i = 0; i < locations.count(); i++) {
this.onLocation(LocationManager.locationFromCLLocation(locations.objectAtIndex(i)));
var location = LocationManager.locationFromCLLocation(locations.objectAtIndex(i));
if (this.maximumAge) {
if (location.timestamp.valueOf() + this.maximumAge > new Date().valueOf()) {
this.onLocation(location);
}
}
else {
this.onLocation(location);
}
}
},