Periodically polling user location on mobile


I’m planning on building my Meteor application for iOS/Android. Say I have a user with an attribute user.time : 9/24/2015 09:15. I’ve been able to get GPS coordinates using the geolocation package on desktop, but I want to be able to get the user’s location on mobile, starting at that time, and then poll periodically (maybe every few minutes) for the next hour or so. How can I do this? Kind of at a loss on where to begin tackling this, as I haven’t seen any tutorials on models where the server requests data from the client (at least I think that’s how you would approach this). Also if anyone has any resources on creating background processes (I guess this could be another approach, although I don’t even know if you can do that), that would be awesome.

Meteor(React) : GPS based tracking for checkout

I’m kind of confused at what your asking here. You say you want to be able to poll a mobile device’s GPS every few minutes.

To tackle that you can use mdg’s geolocation package, or a shameless plug, mine : geolocation-plus. These will provide you with foreground tracking.

If you want true background tracking for elongated periods of time you will also need to use a background plugin such as Background-Geolocation. With the background tracker, you can post these update to your server (android) and use callbacks and meteor calls (ios).

However, if your asking how to request a location update via the server, from the client (the client must be connected and online for this to work obviously. You can check out Streamy or there is another package to set up’s on the client that you can call on the server, which im blanking on right now.


The main functionality I’m looking for here is to be able to get the user’s coordinates, triggered at a certain time, while they don’t have the app open.

It looks like Background-Geolocation is what I’m after, unless I’m missing something. What’s the advantage of foreground tracking?


Foreground / Background are simply two states that an app can be in. Foreground means the cordova application launched (you can see the UI) with the screen unlocked. Background means either the screen is locked or the user has put the app in the background or launched another application. You cannot use navigator.geolocation (foreground) consistently in the background because your app process will be destroyed at some point by the operating system and the foreground tracking is attached to your app process. The background plugin I linked is specifically built to get around this limitation, which works differently based on which platform your running it on (Android / iOS).



I’m also interested in how you would go about to implement functionality to be triggered periodicly (for example, have a function executed every monday of the year) not specifically geo location tho but figured this is similar to what i’m looking for



There are many ways of going about it. But the fact of the matter is you would have to write some native Java / Objective C / Swift to accomplish this, or find a cordova plugin. An example of an alarm plugin that wakes up your app can be found here : What your asking may be more akin to a background service on android.


You wouldn’t be able to run something on the node server?


@linusj Oh if your just looking for a scheduled function to be fired on the server. Go ahead and look at Cron Jobs. They have a nice time parser so you can literally type, do this job ‘every hour’, ‘every 2 hours’, ‘every week’, etc.


You say, “Background means either the screen is locked or the user has put the app in the background or launched another application.” I’m not sure this is what I need. Is there some way to run a background service, not tied to the app? For example, Facebook (at least on Android) pops up notifications continuously, even when the app is not open. Does Cordova offer any such functionality, or am I all on my own to write native code for this sort of thing?


Android yes. iOS, kind of. Through cordova javascript, no. You need a cordova plugin which is written in Java and Objective C (Native) to enable that sort of function.

I’m not sure what your trying to accomplish so this will be general.

Android: Allows you to run something called a service that is completely detached from your main process, you can do anything you want in this service, and even if your main app dies, your service will still run. (Called a Background Service Most of the time).

iOS: More complicated. But basically iOS will allow your app to register for specific events. Lets say you want to work with background geolocation. You can have your app register for significant location update, which I wont explain here. But when the OS registers that you have moved a significant amount of distance it will notify your app through the callback you registered earlier with it, and it will wake up your app and run that code. There are other hacks which i’ve had personal experience that allow for some continuous background processing.

Either way you go, there might be a plugin that does what you need. If you cant find one that does what you need then you’ll need to write your own native code.


Just leaving a note here for anyone that finds this thread. You can use my background plugin now: