Assuming this is only an Android platform, as @Joerg says correctly, you can use cordova.plugins.diagnostic to check if GPS is isGpsLocationEnabled() using isGpsLocationEnabled() :
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){ console.log("GPS location is " + (enabled ? "enabled" : "disabled")); }, function(error){ console.error("The following error occurred: "+error); });
If GPS is disabled as a result, you can switch the user to the location settings page to manually enable GPS:
cordova.plugins.diagnostic.switchToLocationSettings();
Or, in addition, you can use cordova-plugin-request-location-accuracy to request high-precision mode (e.g. GPS) directly from the application. This will display a confirmation dialog, and if the user agrees, GPS will be turned on automatically:
function onRequestSuccess(success){ console.log("Successfully requested accuracy: "+success.message); } function onRequestFailure(error){ console.error("Accuracy request failed: error code="+error.code+"; error message="+error.message); if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){ if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){ cordova.plugins.diagnostic.switchToLocationSettings(); } } } cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
source share