1

Which is the best way to detect if GPS is on or off with phonegap?
I'm using this: https://github.com/BastienL/GPSDetector and works great.

On Android 4.x works all correctly, but on Android 2.x I have a problem:

Seems that the problem is in this row:

gpsDetect = cordova.require('cordova/plugin/gpsDetectionPlugin');

with this error:

02-26 22:54:59.181: E/Web Console(821): module cordova/plugin/gpsDetectionPlugin not found at undefined:0

My code:

        //Check GPS On/Off
    function checkGPS(){
       var gpsDetect = cordova.require('cordova/plugin/gpsDetectionPlugin');
       gpsDetect.checkGPS(onGPS, onGPSError);
    }
    function onGPS(r){
        if(!r){
            Backbone.history.navigate('/errors/gps/', {trigger: true});
            return;
        }
        return true;
    }
    function onGPSError(){
        Backbone.history.navigate('/errors/gps/', {trigger: true});
        return;
    }

Any hints/ideas?

Thanks.

beddamadre
  • 1,583
  • 2
  • 19
  • 40

1 Answers1

0

I'm the developper of this plugin. I just tested it on an Android 2.2 emulator and I can't get your problem. What about this post : module cordova/plugin/ios/nativecomm not found - PhoneGap 2.1 / Sencha 2.0 ? It's for iOS but the problem seems to be the same, so you can try his trick : use a console.log() instead of an alert() in the onGPSError() function. Does the problem persist ?

Community
  • 1
  • 1
Bastien Libersa
  • 680
  • 8
  • 20
  • Hi Bastien, thanks for the reply. I have updated my code on my question. Take a look. – beddamadre Feb 27 '13 at 09:30
  • I had two little errors in the JS part of the plugin (two ";" missing). I just fixed them on GitHub. Go grab the lastest JS file and tell me ;) – Bastien Libersa Feb 27 '13 at 09:52
  • Same error man. 02-27 13:21:56.250: E/Web Console(1965): module cordova/plugin/gpsDetectionPlugin not found at undefined:0 – beddamadre Feb 27 '13 at 12:22
  • Could it be an issue with Backbone and Cordova 2.2 ? Are the other PhoneGap plugins working on your Android 2.X ? Are you using any other JS frameworks (such as RequireJS) for example ? Did you try to run my sample app on your Android 2.X ? Did it work ? – Bastien Libersa Feb 27 '13 at 13:08
  • Yes, I'm using another plugin: ChildBrowser and it works great. I'm using RequireJS also. If I run your single project, it works great. Maybe is a path include error? Because is in this line: var gpsDetect = cordova.require('cordova/plugin/gpsDetectionPlugin'); – beddamadre Feb 27 '13 at 15:06
  • If my sample project works great on your Android 2.X, it means that there is a compatibility problem between your code and mine. But if I can't see your code I can't know what's happening. Could you host your code somewhere so that I can test it ? – Bastien Libersa Feb 27 '13 at 15:53
  • It's a huge code, I can't share it now… btw I'v found another error on android 2.x: 02-27 21:55:33.661: E/Web Console(1251): ReferenceError: Can't find variable: cordova at file:///android_asset/www/js/cordova-plugins/gpsDetectionPlugin.js:1 Maybe it's a require/shim problem? – beddamadre Feb 27 '13 at 21:00
  • I think so, I know there can have some issues while trying to use Require and Cordova together. What about this post : http://stackoverflow.com/questions/13233301/cordova-2-2-0-on-ios-requirejs-wont-load-cordova-correctly ? – Bastien Libersa Feb 28 '13 at 08:14
  • Did you solve your problem? Could you give the fix so that we can close the topic ? – Bastien Libersa Mar 06 '13 at 08:21
  • Hi Bastien, not yet. I don't have time to stay on this in these weeks… if I solve, I'll put here the fix. – beddamadre Mar 13 '13 at 22:15