summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-geolocation/src
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-geolocation/src')
-rw-r--r--StoneIsland/plugins/cordova-plugin-geolocation/src/android/Geolocation.java107
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-geolocation/src/firefoxos/GeolocationProxy.js0
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.h0
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m65
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.cpp34
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.h0
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-geolocation/src/windows/GeolocationProxy.js172
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-geolocation/src/wp/GeoLocation.cs0
8 files changed, 264 insertions, 114 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/android/Geolocation.java b/StoneIsland/plugins/cordova-plugin-geolocation/src/android/Geolocation.java
new file mode 100644
index 00000000..6452170a
--- /dev/null
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/android/Geolocation.java
@@ -0,0 +1,107 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+
+package org.apache.cordova.geolocation;
+
+import android.content.pm.PackageManager;
+import android.Manifest;
+import android.os.Build;
+
+import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaArgs;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.PermissionHelper;
+import org.apache.cordova.PluginResult;
+import org.apache.cordova.LOG;
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import javax.security.auth.callback.Callback;
+
+public class Geolocation extends CordovaPlugin {
+
+ String TAG = "GeolocationPlugin";
+ CallbackContext context;
+
+ String [] permissions = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION };
+
+
+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
+ LOG.d(TAG, "We are entering execute");
+ context = callbackContext;
+ if(action.equals("getPermission"))
+ {
+ if(hasPermisssion())
+ {
+ PluginResult r = new PluginResult(PluginResult.Status.OK);
+ context.sendPluginResult(r);
+ return true;
+ }
+ else {
+ PermissionHelper.requestPermissions(this, 0, permissions);
+ }
+ return true;
+ }
+ return false;
+ }
+
+
+ public void onRequestPermissionResult(int requestCode, String[] permissions,
+ int[] grantResults) throws JSONException
+ {
+ PluginResult result;
+ //This is important if we're using Cordova without using Cordova, but we have the geolocation plugin installed
+ if(context != null) {
+ for (int r : grantResults) {
+ if (r == PackageManager.PERMISSION_DENIED) {
+ LOG.d(TAG, "Permission Denied!");
+ result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION);
+ context.sendPluginResult(result);
+ return;
+ }
+
+ }
+ result = new PluginResult(PluginResult.Status.OK);
+ context.sendPluginResult(result);
+ }
+ }
+
+ public boolean hasPermisssion() {
+ for(String p : permissions)
+ {
+ if(!PermissionHelper.hasPermission(this, p))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /*
+ * We override this so that we can access the permissions variable, which no longer exists in
+ * the parent class, since we can't initialize it reliably in the constructor!
+ */
+
+ public void requestPermissions(int requestCode)
+ {
+ PermissionHelper.requestPermissions(this, requestCode, permissions);
+ }
+
+
+
+}
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/firefoxos/GeolocationProxy.js b/StoneIsland/plugins/cordova-plugin-geolocation/src/firefoxos/GeolocationProxy.js
index e4b40529..e4b40529 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/firefoxos/GeolocationProxy.js
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/firefoxos/GeolocationProxy.js
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.h b/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.h
index cce2738f..cce2738f 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.h
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.h
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m b/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m
index 8b543c8e..e4b34a11 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/ios/CDVLocation.m
@@ -122,17 +122,17 @@
NSUInteger code = [CLLocationManager authorizationStatus];
if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) { //iOS8+
__highAccuracyEnabled = enableHighAccuracy;
- if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){
- [self.locationManager requestAlwaysAuthorization];
- } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
- [self.locationManager requestWhenInUseAuthorization];
+ if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]){
+ [self.locationManager requestWhenInUseAuthorization];
+ } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
+ [self.locationManager requestAlwaysAuthorization];
} else {
NSLog(@"[Warning] No NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key is defined in the Info.plist file.");
}
return;
}
#endif
-
+
// Tell the location manager to start notifying us of location updates. We
// first stop, and then start the updating to ensure we get at least one
// update, even if our location did not change.
@@ -148,9 +148,8 @@
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
} else {
__highAccuracyEnabled = NO;
- // TODO: Set distance filter to 10 meters? and desired accuracy to nearest ten meters? arbitrary.
self.locationManager.distanceFilter = 10;
- self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
+ self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
}
}
@@ -193,35 +192,37 @@
- (void)getLocation:(CDVInvokedUrlCommand*)command
{
- NSString* callbackId = command.callbackId;
- BOOL enableHighAccuracy = [[command argumentAtIndex:0] boolValue];
+ [self.commandDelegate runInBackground:^{
+ NSString* callbackId = command.callbackId;
+ BOOL enableHighAccuracy = [[command argumentAtIndex:0] boolValue];
- if ([self isLocationServicesEnabled] == NO) {
- NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
- [posError setObject:[NSNumber numberWithInt:PERMISSIONDENIED] forKey:@"code"];
- [posError setObject:@"Location services are disabled." forKey:@"message"];
- CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:posError];
- [self.commandDelegate sendPluginResult:result callbackId:callbackId];
- } else {
- if (!self.locationData) {
- self.locationData = [[CDVLocationData alloc] init];
- }
- CDVLocationData* lData = self.locationData;
- if (!lData.locationCallbacks) {
- lData.locationCallbacks = [NSMutableArray arrayWithCapacity:1];
- }
+ if ([self isLocationServicesEnabled] == NO) {
+ NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
+ [posError setObject:[NSNumber numberWithInt:PERMISSIONDENIED] forKey:@"code"];
+ [posError setObject:@"Location services are disabled." forKey:@"message"];
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:posError];
+ [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+ } else {
+ if (!self.locationData) {
+ self.locationData = [[CDVLocationData alloc] init];
+ }
+ CDVLocationData* lData = self.locationData;
+ if (!lData.locationCallbacks) {
+ lData.locationCallbacks = [NSMutableArray arrayWithCapacity:1];
+ }
- if (!__locationStarted || (__highAccuracyEnabled != enableHighAccuracy)) {
- // add the callbackId into the array so we can call back when get data
- if (callbackId != nil) {
- [lData.locationCallbacks addObject:callbackId];
+ if (!__locationStarted || (__highAccuracyEnabled != enableHighAccuracy)) {
+ // add the callbackId into the array so we can call back when get data
+ if (callbackId != nil) {
+ [lData.locationCallbacks addObject:callbackId];
+ }
+ // Tell the location manager to start notifying us of heading updates
+ [self startLocation:enableHighAccuracy];
+ } else {
+ [self returnLocationInfo:callbackId andKeepCallback:NO];
}
- // Tell the location manager to start notifying us of heading updates
- [self startLocation:enableHighAccuracy];
- } else {
- [self returnLocationInfo:callbackId andKeepCallback:NO];
}
- }
+ }];
}
- (void)addWatch:(CDVInvokedUrlCommand*)command
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.cpp b/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.cpp
index c820cfef..3d40ab4c 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.cpp
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.cpp
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2013 Canonical Ltd.
+ * Copyright 2013-2016 Canonical Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,11 +21,19 @@
#include "geolocation.h"
-Geolocation::Geolocation(Cordova *cordova): CPlugin(cordova),
- _geoPositionInfoSource(QGeoPositionInfoSource::createDefaultSource(this)) {
+Geolocation::Geolocation(Cordova *cordova)
+ : CPlugin(cordova),
+ _geoPositionInfoSource(QGeoPositionInfoSource::createDefaultSource(this)) {
if (_geoPositionInfoSource.data() != 0) {
- QObject::connect(_geoPositionInfoSource.data(), SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
- QObject::connect(_geoPositionInfoSource.data(), SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
+ QObject::connect(_geoPositionInfoSource.data(),
+ SIGNAL(positionUpdated(QGeoPositionInfo)),
+ this,
+ SLOT(positionUpdated(QGeoPositionInfo)));
+
+ QObject::connect(_geoPositionInfoSource.data(),
+ SIGNAL(updateTimeout()),
+ this,
+ SLOT(updateTimeout()));
}
}
@@ -81,16 +89,22 @@ void Geolocation::positionUpdated(const QGeoPositionInfo &update) {
p.insert("latitude", coordinate.latitude());
p.insert("longitude", coordinate.longitude());
- p.insert("altitude", coordinate.altitude());
- if (update.hasAttribute(QGeoPositionInfo::VerticalAccuracy))
- p.insert("accuracy", update.attribute(QGeoPositionInfo::VerticalAccuracy));
+ if (coordinate.type() == QGeoCoordinate::Coordinate3D)
+ p.insert("altitude", coordinate.altitude());
+
+ if (update.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
+ p.insert("accuracy", update.attribute(QGeoPositionInfo::HorizontalAccuracy));
+
if (update.hasAttribute(QGeoPositionInfo::Direction))
p.insert("heading", update.attribute(QGeoPositionInfo::Direction));
+
if (update.hasAttribute(QGeoPositionInfo::GroundSpeed))
p.insert("velocity", update.attribute(QGeoPositionInfo::GroundSpeed));
- if (update.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
- p.insert("altitudeAccuracy", update.attribute(QGeoPositionInfo::HorizontalAccuracy));
+
+ if (update.hasAttribute(QGeoPositionInfo::VerticalAccuracy))
+ p.insert("altitudeAccuracy", update.attribute(QGeoPositionInfo::VerticalAccuracy));
+
p.insert("timestamp", update.timestamp().toMSecsSinceEpoch());
for (const QString &id: _id2sc.keys()) {
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.h b/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.h
index 7345bec9..7345bec9 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.h
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/ubuntu/geolocation.h
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/windows/GeolocationProxy.js b/StoneIsland/plugins/cordova-plugin-geolocation/src/windows/GeolocationProxy.js
index 9cab6a4d..03ed4950 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/windows/GeolocationProxy.js
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/windows/GeolocationProxy.js
@@ -14,27 +14,48 @@
* limitations under the License.
*/
-var PositionError = require('./PositionError'),
- ids = {},
- loc;
+/* global Windows, WinJS */
-function ensureLocator() {
- if (loc == null)
- loc = new Windows.Devices.Geolocation.Geolocator();
+var PositionError = require('./PositionError');
+var callbacks = {};
+var locs = {};
- return loc;
+// constants
+var FALLBACK_EPSILON = 0.001;
+
+function ensureAndCreateLocator() {
+ var deferral;
+
+ var loc = new Windows.Devices.Geolocation.Geolocator();
+
+ if (typeof Windows.Devices.Geolocation.Geolocator.requestAccessAsync === 'function') {
+ deferral = Windows.Devices.Geolocation.Geolocator.requestAccessAsync().then(function (result) {
+ if (result === Windows.Devices.Geolocation.GeolocationAccessStatus.allowed) {
+ return loc;
+ }
+
+ return WinJS.Promise.wrapError({
+ code: PositionError.PERMISSION_DENIED,
+ message: 'Geolocation access has not been allowed by user.'
+ });
+ });
+ } else {
+ deferral = WinJS.Promise.wrap(loc);
+ }
+
+ return deferral;
}
-function createErrorCode() {
+function createErrorCode(loc) {
switch (loc.locationStatus) {
case Windows.Devices.Geolocation.PositionStatus.initializing:
// This status indicates that a location device is still initializing
case Windows.Devices.Geolocation.PositionStatus.noData:
- // No location data is currently available
+ // No location data is currently available
case Windows.Devices.Geolocation.PositionStatus.notInitialized:
// This status indicates that the app has not yet requested
- // location data by calling GetGeolocationAsync() or
- // registering an event handler for the positionChanged event.
+ // location data by calling GetGeolocationAsync() or
+ // registering an event handler for the positionChanged event.
case Windows.Devices.Geolocation.PositionStatus.notAvailable:
// Location is not available on this version of Windows
return PositionError.POSITION_UNAVAILABLE;
@@ -55,8 +76,8 @@ function createResult(pos) {
velocity: pos.coordinate.speed,
altitudeAccuracy: pos.coordinate.altitudeAccuracy,
timestamp: pos.coordinate.timestamp
- }
-
+ };
+
if (pos.coordinate.point) {
res.latitude = pos.coordinate.point.position.latitude;
res.longitude = pos.coordinate.point.position.longitude;
@@ -66,55 +87,54 @@ function createResult(pos) {
res.longitude = pos.coordinate.longitude;
res.altitude = pos.coordinate.altitude;
}
-
+
return res;
}
module.exports = {
getLocation: function (success, fail, args, env) {
- ensureLocator();
- if (loc != null)
- {
- var highAccuracy = args[0],
- maxAge = args[1];
+ ensureAndCreateLocator().done(function (loc) {
+ if (loc) {
+ var highAccuracy = args[0],
+ maxAge = args[1];
- loc.desiredAccuracy = highAccuracy ?
- Windows.Devices.Geolocation.PositionAccuracy.high :
- Windows.Devices.Geolocation.PositionAccuracy.default;
+ loc.desiredAccuracy = highAccuracy ?
+ Windows.Devices.Geolocation.PositionAccuracy.high :
+ Windows.Devices.Geolocation.PositionAccuracy.default;
- loc.reportInterval = maxAge ? maxAge : 0;
+ loc.reportInterval = maxAge ? maxAge : 0;
- loc.getGeopositionAsync().then(
- function (pos) {
- success(createResult(pos));
- },
- function (err) {
- fail({
- code: createErrorCode(),
- message: err.message
- });
- }
- );
- }
- else
- {
- fail({
- code: PositionError.POSITION_UNAVAILABLE,
- message: "You do not have the required location services present on your system."
- });
- }
+ loc.getGeopositionAsync().then(
+ function (pos) {
+ success(createResult(pos));
+ },
+ function (err) {
+ fail({
+ code: createErrorCode(loc),
+ message: err.message
+ });
+ }
+ );
+ }
+ else {
+ fail({
+ code: PositionError.POSITION_UNAVAILABLE,
+ message: "You do not have the required location services present on your system."
+ });
+ }
+ }, fail);
},
addWatch: function (success, fail, args, env) {
- ensureLocator();
- var clientId = args[0],
- highAccuracy = args[1],
+ ensureAndCreateLocator().done(function (loc) {
+ var clientId = args[0];
+ var highAccuracy = args[1];
- onPositionChanged = function (e) {
- success(createResult(e.position), {keepCallback: true});
- },
+ var onPositionChanged = function (e) {
+ success(createResult(e.position), { keepCallback: true });
+ };
- onStatusChanged = function (e) {
+ var onStatusChanged = function (e) {
switch (e.status) {
case Windows.Devices.Geolocation.PositionStatus.noData:
case Windows.Devices.Geolocation.PositionStatus.notAvailable:
@@ -131,44 +151,52 @@ module.exports = {
});
break;
- case Windows.Devices.Geolocation.PositionStatus.initializing:
- case Windows.Devices.Geolocation.PositionStatus.ready:
+ // case Windows.Devices.Geolocation.PositionStatus.initializing:
+ // case Windows.Devices.Geolocation.PositionStatus.ready:
default:
break;
}
};
- loc.desiredAccuracy = highAccuracy ?
- Windows.Devices.Geolocation.PositionAccuracy.high :
- Windows.Devices.Geolocation.PositionAccuracy.default;
+ loc.desiredAccuracy = highAccuracy ?
+ Windows.Devices.Geolocation.PositionAccuracy.high :
+ Windows.Devices.Geolocation.PositionAccuracy.default;
- if (cordova.platformId == 'windows' && WinJS.Utilities.isPhone) {
- // on Windows Phone 8.1 'positionchanged' event fails with error below if movementThreshold is not set
- // JavaScript runtime error: Operation aborted
- // You must set the MovementThreshold property or the ReportInterval property before adding event handlers.
- // WinRT information: You must set the MovementThreshold property or the ReportInterval property before adding event handlers
- loc.movementThreshold = loc.movementThreshold || 1; // 1 meter
- }
+ if (cordova.platformId == 'windows') {
+ // 'positionchanged' event fails with error below if movementThreshold is not set
+ // JavaScript runtime error: Operation aborted
+ // You must set the MovementThreshold property or the ReportInterval property before adding event handlers.
+ // WinRT information: You must set the MovementThreshold property or the ReportInterval property before adding event handlers
+ if (Number.EPSILON) {
+ loc.movementThreshold = Number.EPSILON;
+ } else {
+ loc.movementThreshold = FALLBACK_EPSILON;
+ }
+ }
- loc.addEventListener("positionchanged", onPositionChanged);
- loc.addEventListener("statuschanged", onStatusChanged);
+ loc.addEventListener("positionchanged", onPositionChanged);
+ loc.addEventListener("statuschanged", onStatusChanged);
- ids[clientId] = { pos: onPositionChanged, status: onStatusChanged };
+ callbacks[clientId] = { pos: onPositionChanged, status: onStatusChanged };
+ locs[clientId] = loc;
+ }, fail);
},
clearWatch: function (success, fail, args, env) {
- var clientId = args[0],
- callbacks = ids[clientId];
+ var clientId = args[0];
+ var callback = callbacks[clientId];
+ var loc = locs[clientId];
- if (callbacks) {
- loc.removeEventListener("positionchanged", callbacks.pos);
- loc.removeEventListener("statuschanged", callbacks.status);
+ if (callback && loc) {
+ loc.removeEventListener("positionchanged", callback.pos);
+ loc.removeEventListener("statuschanged", callback.status);
- delete ids[clientId];
+ delete callbacks[clientId];
+ delete locs[clientId];
}
- success && success();
+ success();
}
};
-require("cordova/exec/proxy").add("Geolocation", module.exports); \ No newline at end of file
+require("cordova/exec/proxy").add("Geolocation", module.exports);
diff --git a/StoneIsland/plugins/cordova-plugin-geolocation/src/wp/GeoLocation.cs b/StoneIsland/plugins/cordova-plugin-geolocation/src/wp/GeoLocation.cs
index 42af72de..42af72de 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-geolocation/src/wp/GeoLocation.cs
+++ b/StoneIsland/plugins/cordova-plugin-geolocation/src/wp/GeoLocation.cs