transistorsoft / cordova-background-geolocation-SampleApp

Cordova Background Geolocation Sample Application
https://www.transistorsoft.com/shop/products/cordova-background-geolocation
MIT License
122 stars 78 forks source link

Hi I am using this plugin but custom locationTemplate is not working. #120

Closed himanshu849 closed 4 years ago

himanshu849 commented 4 years ago

I want to post the data into server in following format.

[{ latitude: lat, longitude: lng, dt: timeStamp, userId: this.userId, deviceId: this.deviceID }]

please let me know how to format data like above using 'locationTemplate'.

my code is here please look.

BackgroundGeolocation.ready( { reset: true, debug: true, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 0, locationUpdateInterval: 10, stopOnTerminate: false, startOnBoot: true, url: this.gps_update_link, autoSync: true, httpRootProperty: '.',

    locationTemplate: '[{"latitude":<%= latitude %>, "longitude":<%= longitude %>}]',
    extras: {
      latitude: this.lat,
      longitude: this.lng,
      deviceId: this.deviceID,
      userId: this.userId
    }
  },

  state => {
    if (!state.enabled) {
      BackgroundGeolocation.start();
    } else {
    }
  }
);

onLocation(location: Location) { console.log('[location] -', location); this.zone.run(() => { this.lat = location.coords.latitude; this.lng = location.coords.longitude; this.timeStamp = new Date(location.timestamp); //this.sendData(this.lat, this.lng, this.timeStamp) });

console.log(location.coords.latitude + ' , ' + location.coords.longitude + ' , ' + location.timestamp);

}

christocracy commented 4 years ago

This the Sample App repo, not the plugin repo. The plugin is here

And please learn to use syntax highlighting. You wrap your multiline code in 3 backticks.