From 211fcc8d4e212d40dd67adf720372c33ce01c3aa Mon Sep 17 00:00:00 2001 From: Stanimir Karoserov Date: Fri, 16 May 2014 13:48:00 +0300 Subject: [PATCH] minor location fixes and updates --- location/location-common.ts | 9 +++++++++ location/location.android.ts | 13 +++++++++++-- location/location.d.ts | 5 +++++ location/location.ios.ts | 12 +++++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/location/location-common.ts b/location/location-common.ts index 5d97b84e4..ba349a84b 100644 --- a/location/location-common.ts +++ b/location/location-common.ts @@ -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"); diff --git a/location/location.android.ts b/location/location.android.ts index cfb9723a4..3a9a3cd70 100644 --- a/location/location.android.ts +++ b/location/location.android.ts @@ -95,9 +95,17 @@ export class LocationManager { var criteria = new android.location.Criteria(); criteria.setAccuracy((this.desiredAccuracy === types.Accuracy.HIGH) ? 1 : 2); this.locationListener = 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; diff --git a/location/location.d.ts b/location/location.d.ts index efdecd83f..ebc632a3b 100644 --- a/location/location.d.ts +++ b/location/location.d.ts @@ -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; diff --git a/location/location.ios.ts b/location/location.ios.ts index d292c84e4..1925be5d6 100644 --- a/location/location.ios.ts +++ b/location/location.ios.ts @@ -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); + } } },