Skip to content

zeroasterisk/meteor-cordova-geolocation-background

Repository files navigation

UPDATE: Source Cordova Package Changed / No longer free for Android / ?API changed?

The Cordova package has changed to background-geolocation-lt. And now the iOS version is free, but you have to pay a fair-bit to get the Android version.

As of now, I don't have a need to update my Meteor wrapper, nor the money to buy the full version. I suspect it's API has changed too. I have only read it's documentation though, not tried it, so I don't know how well this will fair for you... YMMV

I may update this to use the new versions, when I have the need. Feel free to share pull requests with me, or sponser me a license 👍


Meteor + Cordova get Geolocation in Background

This is a Meteor Smart Package which installs the Cordova Background GeoLocation Plugin / on GitHub, and exposes a simpler API to setup, configure, and start/stop the background service.

See an example application using it here.

How it Works

  1. Meteor build Cordova with this Plugin
  2. Meteor configures this Plugin in Cordova (you have to configure)
  3. Meteor can trigger the Background service to get Geolocation (GPS) details
  4. The Cordova Background service periodically POSTs it's data to the Meteor server (not to the client Cordova instance)
  5. Meteor Server can update a Collection (or anything else)
  6. Meteor Client syncs with the server

Install

requires Meteor 0.9.2+

meteor add zeroasterisk:cordova-geolocation-background

Location Data / fields

  • longitude
  • latitude
  • speed
  • accuracy
  • uuid (of the device, if available)
  • userId (of the Meteor.userId, if available)
  • key (simple Meteor.identity key to act as a simple security measure)

Setup Cordova Android

Should be automatic if you configure the Plugin

Setup Cordova iOS

Should be automatic if you configure the Plugin

Setup This Plugin (isCordova on the client)

Here is the "default" config with some notes to help.

Pass in only what you need to overwrite...

You must set the url options.

if (Meteor.isCordova) {
  GeolocationBG.config({
    // your server url to send locations to
    //   YOU MUST SET THIS TO YOUR SERVER'S URL
    //   (see the setup instructions below)
    url: 'http://example.com/api/geolocation',
    params: {
      // will be sent in with 'location' in POST data (root level params)
      // these will be added automatically in setup()
      //userId: GeolocationBG.userId(),
      //uuid:   GeolocationBG.uuid(),
      //device: GeolocationBG.device()
    },
    headers: {
      // will be sent in with 'location' in HTTP Header data
    },
    desiredAccuracy: 10,
    stationaryRadius: 20,
    distanceFilter: 30,
    // Android ONLY, customize the title of the notification
    notificationTitle: 'Background GPS',
    // Android ONLY, customize the text of the notification
    notificationText: 'ENABLED',
    //
    activityType: 'AutomotiveNavigation',
    // enable this hear sounds for background-geolocation life-cycle.
    debug: false
  });
}

No params or headers are required, but you can add whatever you like... which you can use on the server as validation, or as extra data to log/use.

Setup a Receiver on the Meteor Server

You can do this any way you like, but if you're using IronRouter you can implement as described below.

Note, I use the zeroasterisk:throttle package to limit the possible "flooding" of the path to 100 requests every second (scale as needed).

You can test this with curl, you don't even have to fire up Cordova.

curl -v -H "Content-Type: application/json" -X PUT --data '{"device":"curl","location":{"longitude":"-85.70906639098872","recorded_at":"Thu Sep 25 01