Notworck
Notworck

Reputation: 29

Check GPS cordova plugin diagnostic XML.config

I downloaded the plugin cordova.diagnostic but do not understand how to use it and how to install it. I did the download in a project cordova .

  1. Where do I put this string ?

    <gap:plugin name="cordova.plugins.diagnostic" source="plugins.cordova.io" />
    
  2. This code for check GPS :

    cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
    console.log("Location is " + (enabled ? "enabled" : "disabled"));
    }, function(error){
        console.error("The following error occurred: "+error);
    });
    

    How do you use it ? I tried to put it in the code but when I start the app , nothing happens.

  3. I have to put something in the www folder ?

Please do not give me the link with the guidance of the plugin on mpm , it does not work and it is not clear.

Upvotes: 0

Views: 2460

Answers (1)

DaveAlden
DaveAlden

Reputation: 30356

  1. Where do I put this string ?

In the cordova project's config.xml

  1. How do you use it ? I tried to put it in the code but when I start the app , nothing happens.

Use it as in the code above. Probably not working because plugin is not installed correctly. Connect a remote debugger and check cordova.plugins.diagnostic object exists; if not, plugin is not installed correctly

  1. I have to put something in the www folder ?

No. If the plugin is installed correctly, cordova will do this for you at build time.

Please do not give me the link with the guidance of the plugin on mpm , it does not work and it is not clear.

I authored this plugin; there is clear instructions on the Github page on how to install it:

Add the following xml to your config.xml to use the latest version of this plugin from the Cordova Registry:

<gap:plugin name="cordova.plugins.diagnostic" source="plugins.cordova.io" />

or from npm:

<gap:plugin name="cordova.plugins.diagnostic" source="npm" />

And how to use it:

isLocationEnabled()

Checks if app is able to access location. On iOS this returns true if both the device setting for location is on AND the application is authorized to use location. On Android this returns true if Location setting is ON AND Location mode is set to "High Accuracy" (GPS).

cordova.plugins.diagnostic.isLocationEnabled(successCallback, errorCallback);
Parameters
  • {function} successCallback - The callback which will be called when diagnostic of location is successful. This callback function have a boolean param with the diagnostic result.
  • {function} errorCallback - The callback which will be called when diagnostic of location encounters an error. This callback function have a string param with the error.
Example usage
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
    console.log("Location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});

Additionally, there is an example project which illustrates exactly how to use the plugin in an example application.

Upvotes: 2

Related Questions