Add: LocationService.hasPermission()
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.3.7-beta-20180713-1416" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.3.7-beta-20180717-1047" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/android/plugin/google/maps/PluginLocationService.java
src/android/plugin/google/maps/PluginLocationService.java
@@ -71,6 +71,8 @@ public class PluginLocationService extends CordovaPlugin {
try {
if ("getMyLocation".equals(action)) {
PluginLocationService.this.getMyLocation(args, callbackContext);
+ } else if ("hasPermission".equals(action)) {
+ PluginLocationService.this.hasPermission(args, callbackContext);
}
} catch (JSONException e) {
@@ -82,6 +84,18 @@ public class PluginLocationService extends CordovaPlugin {
}
+
+
+ @SuppressWarnings("unused")
+ public void hasPermission(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ synchronized (semaphore) {
+ // Check geolocation permission.
+ boolean locationPermission = PermissionChecker.checkSelfPermission(cordova.getActivity().getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PermissionChecker.PERMISSION_GRANTED;
+ callbackContext.success(locationPermission ? 1 : 0);
+ }
+ }
+
+
@SuppressWarnings("unused")
public void getMyLocation(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
synchronized (semaphore) {

MODIFY
src/ios/GoogleMaps/PluginLocationService.h
src/ios/GoogleMaps/PluginLocationService.h
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) NSMutableArray *locationCommandQueue;
- (void)getMyLocation:(CDVInvokedUrlCommand*)command;
+- (void)hasPermission:(CDVInvokedUrlCommand*)command;
@end

MODIFY
src/ios/GoogleMaps/PluginLocationService.m
src/ios/GoogleMaps/PluginLocationService.m
self.lastLocation = nil;
}
+/**
+ * Return 1 if the app has geolocation permission
+ */
+- (void)hasPermission:(CDVInvokedUrlCommand*)command {
+
+ int result = 1;
+ CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
+ if (status == kCLAuthorizationStatusDenied ||
+ status == kCLAuthorizationStatusRestricted) {
+ result = 0;
+ }
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:result];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+
+}
/**
* Return the current position based on GPS
*/

MODIFY
www/LocationService.js
www/LocationService.js
var LatLng = require('./LatLng');
var LocationService = function(exec) {
-
+ function _errorHandler(err) {
+ console.error(err);
+ }
return {
+ hasPermission: function(callback) {
+ var self = this;
+
+ var resolver = function(resolve, reject) {
+ exec.call({
+ _isReady: true
+ },
+ function(hasPermission) {
+ resolve.call(self, hasPermission === 1);
+ },
+ reject.bind(self), 'LocationService', 'hasPermission', [], {sync: true});
+ };
+
+ var errorHandler = function(result) {
+ if (typeof error_callback === "function") {
+ error_callback.call(self, result);
+ } else {
+ (self.errorHandler || _errorHandler).call(self, result);
+ }
+ };
+ if (typeof callback === "function") {
+ resolver(callback, errorHandler);
+ return self;
+ } else {
+ return new Promise(resolver);
+ }
+ },
getMyLocation: function(params, success_callback, error_callback) {
var self = this;
var args = [params || {}, success_callback || null, error_callback];
@@ -33,7 +62,7 @@ var LocationService = function(exec) {
if (typeof error_callback === "function") {
error_callback.call(self, result);
} else {
- self.errorHandler.call(self, result);
+ (self.errorHandler || _errorHandler).call(self, result);
}
};

Add: LocationService.hasPermission() #2350