Search code examples
cordovaphonegap

Cordova Request Location Accuracy Plugin


I want to use Cordova Request Location Accuracy Plugin in my phonegap app i add in my config.xml and then i try to use cordova.plugins.locationAccuracy.request(); but my console throws TypeError: cordova.plugins.locationAccuracy is undefined What am i missing? Thanks!!


Solution

  • If building locally, make sure it's installed in your project:

    $ cordova plugin add cordova-plugin-request-location-accuracy
    

    Or if building in cloud (e.g. Phonegap Build), make sure it's referenced in the config.xml:

    <plugin name="cordova-plugin-request-location-accuracy" spec="*" />
    

    Then make sure you wait for the deviceready event before referencing the plugin, because Cordova dynamically loads the JS plugin components at runtime:

    document.addEventListener("deviceready", function(){
        cordova.plugins.locationAccuracy.request();
    }, false);
    

    Check the plugin documentation for platform-specifics and the example project for an illustration of usage.