Picky: Geosearch 2

ruby / picky / iphone

This is a post in the Picky series on its workings.

In this quick one I’ll be using my own iPhone’s geodata as data for a space/time Picky search.

Lean back and enjoy the screencast.

Enjoy the show

I’ll be searching time and space for my own footprints in Switzerland, Germany and Australia.

Best viewed in full-screen. Warning: Safe for work with the possible exception of my voice, which has in the past triggered attacks by various animals/politicians.

View with subtitles.

(When I say “Apple is collecting”, I mean “‘Apple’ is collecting” – the phone)

So how do you get your iPhone’s geodata?

iPhone geodata

First of all, let me direct you to a nice OSX application: http://petewarden.github.com/iPhoneTracker/ This enables you to view your data nicely.

The third question in the FAQ explains how to get your data out of the phone: How can I examine the data without running the application? (Also look at the updates)

That’s it. At the end you should have access to a SQLite database, from where I extracted CSV data into the file data/iphone_locations.csv (with header data removed).

What did I do with the data?

The code

We’ll first be looking at the server, then at the client.


In the server, define an index like this:

iphone_locations = Index::Memory.new :iphone do
  source Sources::CSV.new(
    file: 'data/iphone_locations.csv'
  ranged_category :timestamp, 86_400, precision: 5, qualifiers: [:ts, :timestamp]
  geo_categories  :latitude, :longitude, 25, precision: 3

As you can see, I’m only using timestamp, latitude and longitude. And wrote all the possible data fields for completeness’ sake if I need to refer to one of these later on.

The timestamp uses a “radius” of 86’400 seconds (a day). That means it includes all results around the given timestamp in a range of ts-1.day..ts+1.day.

It also sets a short qualifier (“ts”) such that the search input field is not completely filled, i.e. searching for “ts:…” is equivalent to searching for “timestamp:…”.

The geodata uses geo_categories (see last post), with 25 km as radius and an average precision of 3 (1 = low, 5 = high).

Now you already could search your data e.g. with curl 'localhost:8080/iphone?query=longitude:8.2'. Note that the timestamp data is saved as seconds since January 1st 2001 (as per the Apple data).


The client actually stayed almost exactly the same since the last blog post, with the geo data piggybacking on the results hash.

The only notable addition is the HTML5 slider, which is a simple input[type=range], with a change listener defined on it, which triggers the insertion of the (“ts:” qualified) search string.

One problem I had was that I did not know that Javascript defines months in the range (0..11), but not the years, so 1977 is 1977, and not 1978, thankfully. But still, quite a stumbling block if you’re unaware of it.


Have fun doing crazy space/time searches!

… and don’t run into time paradoxes. Those are nasty. Watch Back to the Future 1 for tips and tricks. First one is free: Learn to play an electric guitar.


So we’ve seen

  1. how to extract your iPhone’s geodata.
  2. that you can search space/time.
  3. how you might write your own.
  4. that Javascript Date handling – although lauded by many PHP programmers – is crap.

Hope you learnt something new!

Next Phony: Phone Numbers