diff --git a/demo/app/app-root.xml b/demo/app/app-root.xml
new file mode 100644
index 0000000..8d01995
--- /dev/null
+++ b/demo/app/app-root.xml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/demo/app/app.ts b/demo/app/app.ts
index a17b0bd..108a350 100644
--- a/demo/app/app.ts
+++ b/demo/app/app.ts
@@ -1,2 +1,2 @@
import * as application from 'tns-core-modules/application';
-application.start({ moduleName: "main-page" });
+application.run({ moduleName: "app-root" });
diff --git a/demo/app/tests/mock-ios.js b/demo/app/tests/mock-ios.js
index c1f9df3..11dd776 100644
--- a/demo/app/tests/mock-ios.js
+++ b/demo/app/tests/mock-ios.js
@@ -19,6 +19,14 @@ var MockLocationManager = (function () {
return _this._requestSingleUpdate(_this.delegate, _this);
}, 500);
};
+ MockLocationManager.prototype.requestLocation = function () {
+ var _this = this;
+ this.removeUpdates(null);
+ MockLocationManager.intervalId = setTimeout(function () {
+ // this.delegate is the location listener
+ return _this._requestSingleUpdate(_this.delegate, _this);
+ }, 500);
+ };
MockLocationManager.prototype._requestSingleUpdate = function (locListener, instance) {
var newLocation = {
coordinate: {
diff --git a/src/geolocation.ios.ts b/src/geolocation.ios.ts
index 97d900d..3812d00 100644
--- a/src/geolocation.ios.ts
+++ b/src/geolocation.ios.ts
@@ -140,6 +140,10 @@ function errorHandler(errData: UnhandledErrorEventData) {
}
}
+function getVersionMaj () {
+ return parseInt(Platform.device.osVersion.split(".")[0]);
+}
+
// options - desiredAccuracy, updateDistance, minimumUpdateTime, maximumAge, timeout
export function getCurrentLocation(options: Options): Promise {
return new Promise(function (resolve, reject) {
@@ -164,6 +168,7 @@ export function getCurrentLocation(options: Options): Promise {
} else {
let timerId;
let locListener;
+ let initLocation;
let stopTimerAndMonitor = function (locListenerId) {
if (timerId !== undefined) {
@@ -174,18 +179,30 @@ export function getCurrentLocation(options: Options): Promise {
};
let successCallback = function (location: Location) {
- if (typeof options.maximumAge === "number" && location.timestamp.valueOf() + options.maximumAge < new Date().valueOf()) {
- // returned location is too old, but we still have some time before the timeout so maybe wait a bit?
- return;
+ if (getVersionMaj() < 9) {
+ if (typeof options.maximumAge === "number" && location.timestamp.valueOf() + options.maximumAge < new Date().valueOf()) {
+ // returned location is too old, but we still have some time before the timeout so maybe wait a bit?
+ return;
+ }
+
+ if (options.desiredAccuracy !== Accuracy.any && !initLocation) {
+ // regardless of desired accuracy ios returns first location as quick as possible even if not as accurate as requested
+ initLocation = location;
+ return;
+ }
}
stopTimerAndMonitor(locListener.id);
resolve(location);
};
- locListener = LocationListenerImpl.initWithLocationError(successCallback);
+ locListener = LocationListenerImpl.initWithLocationError(successCallback, reject);
try {
- LocationMonitor.startLocationMonitoring(options, locListener);
+ if (getVersionMaj() >= 9) {
+ LocationMonitor.requestLocation(options, locListener);
+ } else {
+ LocationMonitor.startLocationMonitoring(options, locListener);
+ }
} catch (e) {
stopTimerAndMonitor(locListener.id);
reject(e);
@@ -321,6 +338,11 @@ export class LocationMonitor {
return null;
}
+ static requestLocation(options: Options, locListener: any): void {
+ let iosLocManager = getIOSLocationManager(locListener, options);
+ iosLocManager.requestLocation();
+ }
+
static startLocationMonitoring(options: Options, locListener: any): void {
let iosLocManager = getIOSLocationManager(locListener, options);
iosLocManager.startUpdatingLocation();
@@ -342,7 +364,7 @@ export class LocationMonitor {
iosLocManager.distanceFilter = options ? options.updateDistance : minRangeUpdate;
locationManagers[locListener.id] = iosLocManager;
locationListeners[locListener.id] = locListener;
- if (parseInt(Platform.device.osVersion.split(".")[0]) >= 9) {
+ if (getVersionMaj() >= 9) {
iosLocManager.allowsBackgroundLocationUpdates =
options && options.iosAllowsBackgroundLocationUpdates != null ?
options.iosAllowsBackgroundLocationUpdates : false;