
A cron job is a script on the server running periodically at fixed times, dates, or intervals. I've created my cron job in PHP, but you can choose the language you want. What you need is a server which allows to run scripts repeatedly. I'm using the cron job support from my hosting provider, Bluehost. As I'm tracking my position every 10 minutes, the cron job is running at 10 minutes interval to sync the data.

In my PHP script, I'm first reading the JSON feed from SPOT, and the last timestamp from my CartoDB table. Then I'm looping through the tracking points from SPOT, and if the timestamp is newer, I'm adding the point to CartoDB.
You need to add your feed id from SPOT and your CartoDB credentials. Remember to create the table in CartoDB before you run the script! The PHP script is available on Github. Feel free to improve it!
In the next blog post, we'll display the tracking data on a map.
2 comments:
Hi! I found Your blog while searching for solutions to show spot messenger positions. I really like it and think You do some good stuff! :-) I'm a beginner so this might be a bad question. I doesn't understand if Your Github should have included a config.php? And should this config.php specify the spot feedid and maybe more? I would appreciate if You have time to give me a headsup! Kepp up the good work! Best regards, Daniel
Hi Bjørn!
I have recently made a site for a friend of mine, http://roferd.no, that monitors a 3300km one-man rowing expedition around the Norwegian coastline. I am a novice at this but, inspired by your blog, I have managed to prepare a Leaflet map and store the mapping data in CartoDB. I will probably give the syncing part a go very soon too. Maybe you could tell me how I can make Leaflet focus on the active marker only, instead of all the markers (fitBounds)? Best regards, Peter
Post a Comment