Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Using new Cordova Plugins Feature - Geolocation

Happy new build day,

I have a project that uses the Christocracy geo-plugin and have:

  1. Upgraded my libraries to Version3.0

  2. Removed all customizations (where I previously used this plugin) and let Appery re-generate the source.

  3. Brought the Christocrary plugin directly from this location - and then pointed the plugin importer to the plugin. The importer appears to work correctly.

    I've left my code that calls the plug in - the same - however - it no longer starts the background plugin (which is noisy in the log when it starts - and I can see it starting in the xCode debug window )

    Once in - I'm trying to 'use' the plugin - and can't find out how to implement it in my code.

    It does not appear to work with the same name or same calling method - as when I implemented the plugin myself.

    The importer calls the plugin "BackgroundGeolocation" however,m its not addressable in the code using that name.

    How do I tell - how to call a plugin - that's been implemented with the Cordova plugin importer???

    Thanks!
    Bruce

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Using new Cordova Plugins Feature - Geolocation

just so you folks know that I'm persistent - and try to solve my own problems... here's the code that's running to try to start the plugin that Appery brought in.....:

var bgeoon = false;

function fBackgroundGeoCall(location) {
console.log('[js] BackgroundGeoLocation callback: ' + location.latitude + ',' + location.longitude);
localStorage.setItem('s_lat', location.latitude);
localStorage.setItem('s_long', location.longitude);
// insert code here to determine if in current boundar....
var nlat = Number(location.latitude);
var nlong = Number(location.longitude);
var options = {
lat: nlat,
lng: nlong
};
var ocurrentposition = new google.maps.LatLng(nlat, nlong);
console.log('the current position object is:' + ocurrentposition);
}

function fStartGeo() {
//
//
// after deviceready
//
//
//alert('In fwatchmyposition- startup');
var BackgroundGeo;
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 60000
};
try {
console.log('i made it to here......');
BackgroundGeo = window.BackgroundGeoLocation;
console.log('1');
if (BackgroundGeo === undefined && window.plugins !== undefined) {
console.log('trying undefined 1');
BackgroundGeo = window.plugins.BackgroundGeoLocation;
}
console.log('2');

Code: Select all

     if (BackgroundGeo === undefined && plugins !== undefined) { 
         console.log('trying undefined 2'); 
         BackgroundGeo = plugins.BackgroundGeoLocation; 
     } 
     console.log('3'); 
     if (BackgroundGeo === undefined) { 
         console.log('trying undefined 3'); 
         BackgroundGeo = window.bgGeo; 
     } 
     console.log('4'); 

// if (BackgroundGeo === undefined) {
// console.log('trying undefined 4-a');
// BackgroundGeo = bgGeo;
// console.log('was there a syntax error here');
// }
console.log('5');
if (BackgroundGeo === undefined && window.plugins !== undefined) {
console.log('trying undefined 5');
BackgroundGeo = window.plugins.bgGeo;
}
console.log('6');
if (BackgroundGeo === undefined && plugins !== undefined) {
console.log('trying undefined 6');
BackgroundGeo = plugins.bgGeo;
}
console.log('7');
if (BackgroundGeo === undefined) {
console.log('trying undefined 7');
BackgroundGeo = window.BackgroundGeolocation;
}
console.log('8');
// if (BackgroundGeo === undefined) {
// console.log('trying undefined 8');
// BackgroundGeo = BackgroundGeolocation;
// }
console.log('9');
if (BackgroundGeo === undefined && window.plugins !== undefined) {
console.log('trying undefined 9');
BackgroundGeo = window.plugins.BackgroundGeolocation;
}
console.log('10');
if (BackgroundGeo === undefined && plugins !== undefined) {
console.log('trying undefined 10');
BackgroundGeo = plugins.BackgroundGeolocation;
}
console.log('11');
if ( BackgroundGeo === undefined ) {
BackgroundGeo = window.background-geolocation ; }
console.log('what the heck');
console.log('12');
} catch (e) {
console.log(e);
}

Code: Select all

 if (BackgroundGeo !== undefined) { 
     var callbackFn = fBackgroundGeoCall; //function(location) { 

     var failureFn = function(error) { 
         console.log('BackgroundGeoLocation error'); 
     }; 
     // alert('Configuring Geolocation'); 
     // BackgroundGeoLocation is highly configurable. 
     try { 
         BackgroundGeo.configure(callbackFn, failureFn, { 
             desiredAccuracy: 10, 
             stationaryRadius: 20, 
             distanceFilter: 100, 
             notificationTitle: 'Background tracking', //  

Please help...

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Using new Cordova Plugins Feature - Geolocation

balance of the code..

Code: Select all

             notificationText: 'ENABLED', // ); 
 } 

}

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Using new Cordova Plugins Feature - Geolocation

Alright - I figured it out. For those of you that come after me - and want to know - after you have imported a plugin - how to use it in your app - and you are using IOS - you can import your project into xCode - and then look here...

Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Using new Cordova Plugins Feature - Geolocation

in the case of the Christocracy Geo plugin - it's called plugins.backgroundGeoLocation ....

so - the code would be:

var backgroundplugin = plugins.backgroundGeoLocation

backgroundplugin.configure() etc.....

Suggestion to the Appery team - PUT THIS INFORMATION ON THE TAB AFTER IMPORTING THE PLUGIN --- a line on that tab would be:

Plugin Name for Javascript code: plugins.Name of plugin to use

Best,

Bruce

asid
Posts: 0
Joined: Sun Aug 09, 2015 8:01 pm

Using new Cordova Plugins Feature - Geolocation

Thank you for this information.

Return to “Issues”