The Map

Thanks to those modern inventions called smartphones, everybody is carrying a device around, which is packed to the brim with sensors. Some of which, you probably don’t know, what to do with. Like a humidity sensors. Or have you ever thaught: “hmm, I wonder, what’s the humidity in this subway?”. Some people know what to do with those sensors. For example, the NSA can finally track you where ever you are. And they don’t even have to invest into a bug to spy on you. But so can you know, too!

As it turns out, OsmAnd is able to send your current location to a server of your choice at an interval of your choice, through its Trip recording plugin. Unfortunately, the availability of such a server is rather sparse. And you’d want to keep your data to yourself anyway. Privacy and all. Don’t you?

So I wrote handy PHP scripts, to help me with that. They were originally for my brother’s tour through Europe, but serve me quite well, too. There are obviously two parts to the whole tracking thing. Actually tracking, i.e. saving the position and at some later point in time retrieving those positions, to monetize do cool stuff with them.

The tracking stuff couldn’t be easier, OsmAnd simply queries a configured URL using http(s) periodically. It submits Latitude, Longitude, Time, hdop (whatever that was, I forgot. But let’s save it anyway. Big Data fuck yeah!), Altitude, Speed and Bearing as part of the URLs path. In addition, my PHP tracking script require a trip name, by which data sets are later grouped and can be queried, a username and corresponding key for authentication. Everything gets saved into a (MySQL) database and you are done! I have all your delicous datas now! Muhahahaha!

Now comes the more interesting part. Actually doing something with that data… For starters, at least visualizing it. Maybe on some kind of a map. Maybe even on the Internet. So others can look at it, too. Best using something free and open source. Because that’s important. Even if you don’t think so… I do. Time for uMap. uMap (open source: check) “lets you create maps with OpenStreetMap [(open source: check)] layers in a minute and embed them in your site [(open source: check)].” Win, win and win!

There are several instances of it available online. See the OSM-Wiki entry. And better yet, you could just host an instance yourself. Which I wanted to, but unfortunately didn’t manage to do. Shame on me. So I’m using the instance at umap.openstreetmap.fr. With the possibility to migrate to my one, at some point. 😉

Now, how can I make uMap on some other server, use the data in my database. I certainly don’t what to give it direct access to it… That would be stupid and not supported by uMap. What it does support, however, is displaying remote data, queried from another server in formats like KML, GeoJSON or gpx, among others. So I wrote the second part to my PHP tracking script.

Given a valid user and trip name, it delivers all a GeoJSON object, containing all saved points corresponding to that user and trip. And that’s basically it. There is some more stuff going on in there though. As it turned out, big data can be quite big. So as trip grow longer, the data set grows bigger. Duh! So I had to make some precautions. Currently, they are quite simple and probably need more thinking later on. But for now, they work.

At the moment they include being able to specify the bounding box of the map section you want to show and being able to reduce points, that are in a certain distance of each other into one point.

Recently, I tried to automatically split a trip into different tracks. A trip is split into a new track, when to consecutive measurements are more than an hour apart. Additionally, the length of each such track is calculated, which can be seen in addition to start and end date, if you click on a track section.

However, there are still some downsides to the solution. For one, and that’s by far the worst, if you don’t have a mobile Internet connection and can’t reach your tracking server, OsmAnd just drops the measurement and it is lost forever… Secondly, and that is more like a nuisance, uMap only seems to allow coloring tracks by map layer. Which means, I’m not able to specify a color in the GeoJSON, for example to differentiate the different tracks of a trip. Bummer…

But I guess nobody of you cared about all that anyway… So here you have The Map of my NZ trip. Happy Stalking!