get unstuck, in time

29 June 2009

Locatable and iPhone 3.0 issues

Several people have reported that Locatable -- I think Relocatable, actually -- is not working on iPhone OS 3.0. I haven't had a chance to debug yet but consider this an open thread to complain and/or troubleshoot.
Note that Apple has now built the Geolocation API into the Mobile Safari browser in 3.0 using the standard navigator.geolocation object. Looks like Locatable was just ahead of its time!

Labels: , , ,

23 December 2008

FireEagle + Relocatable

Last month I was fortunate enough to see a presentation at Google headquarters UK from Yahoo!'s FireEagle team, part of the inaugural location-based developer meetup session.  (That's right, not only did Google let Yahoo!s in the building, they even gave them food and drink -- of course, we all had to sign an NDA to get into the meeting room, presumably so we wouldn't wander about jotting down random scrawlings on people's whiteboards).  As you might know, FireEagle is a permission-based location storage service.  It's sort of like a depot where you can save your most recent location, and allow other (FireEagle-enabled) web sites and services to access it.  They are apparently close to launching a Facebook application, for example, that lets you locate anyone in your friends list who has a FireEagle account.
There are several FireEagle-related apps in the AppStore but they also suffer from the Apple restriction of not being able to run in the background, a condition that can only be avoided on a jailbroken phone.  This is exactly the scenario that got me to write the Relocatable application in the first place, and sadly, it's not one that is likely to be resolved soon.
For those of you who are interested in always-on updates to FireEagle via your iPhone, Robbie over at has a recipe for you.  He goes through the full process, including jailbreaking, installing Locatable/Relocatable, and setting up some python scripts to send your location data to FireEagle automatically.  Good stuff!
Speaking of FireEagle, I'd love to see a web-only solution also, using the W3C API and Locatable.  This would be more of an on-demand app, e.g. a bookmark for iPhone Safari that when loaded would save your current location.  Any takers?  Let me know and I'll put a link up here.

Labels: , , ,

27 August 2008

Changelog for Locatable 0.3

I'm just about to submit the new version of Locatable. Here are the changes: Locatable
  • More accurate GPS readings. When retrieving a location, wait until the accuracy is within the specified range, or 20 seconds, whichever comes first (i.e. if you set it to "Best", it'll spend the full 20 seconds).
  • New option "Expire after" specifies how stale of a location is allowed to be sent to web sites. Default is 10 minutes. If you set this to "each request", Locatable will pop up every time a web site wants to read your location.
  • New option "Ask permission" defines if and how many times you'll be prompted to allow a site to see your location. Default is to always ask. Set this to "Twice per site" to mimic the behaviour of iPhone native apps.
  • Relocatable is now a daemon process. You can control how often and how fast it runs by editing /System/Library/LaunchDaemons/com.tralfamadore.locatable.plist.
  • You can also run it from the command line (it now lives in /usr/libexec/relocatable), which gives you the following options:
~ root# /usr/libexec/relocatable/Relocatable -h
Usage: Relocatable [-v] [-t SECONDS] [-d SECONDS] [-e CMD]
-d SECONDS      run as a daemon, delay specified seconds between fixes
-e CMD          execute given program (with args) after each location fix,
                 can include @lat@, @long@, and @hacc@ tokens
-t SECONDS      spend specified seconds waiting for a fix, default 30
-v              turn on verbose logging
Let me know if you encounter any issues. Update (30 Aug 08): A few people had questions about getting the command execution piece to work. Here's an example — the important bit is to wrap the whole command in single quotes, otherwise the shell gets confused. First, if Relocatable is already running as a daemon (it will be by default), you need to stop it:
~ root# launchctl unload /System/Library/LaunchDaemons/com.tralfamadore.locatable.plist
Once that's done, you can run Relocatable as a one-off from the command line:
~ root# /usr/libexec/relocatable/Relocatable -v \
> -e 'curl ""'
Opened LBS database for read...
Started updates...
newLocation: <+51.xxxxxxxxx, -0.xxxxxxxx> +/- 93.21m @ 2008-08-30 13:17:44 +0100
newLocation: <+51.xxxxxxxxx, -0.xxxxxxxx> +/- 93.21m @ 2008-08-30 13:18:29 +0100
Stopped updates
Opened LBS database for write...
* About to connect() to port 80 (#0)
*   Trying connected
* Connected to ( port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.17.1 (arm-apple-darwin9) libcurl/7.17.1 OpenSSL/0.9.8g zlib/1.2.3
Note the use of the single quotes (to bracket the command passed to Relocatable) and double quotes (to bracket the URL, so it can contain characters that would otherwise confuse the shell, like the ampersand). The same rules regarding quoting apply to editing the daemon plist. Once you're happy with your settings and have edited the plist to your satisfaction, remember to start it back up:
~ root# launchctl load /System/Library/LaunchDaemons/com.tralfamadore.locatable.plist

Labels: , , , ,

21 August 2008

Location tracking using Relocatable

"Relocatable" is the location-gathering daemon add-on to "Locatable" (currently they're bundled together for distribution purposes on Cydia; an AppStore version will only contain Locatable as it's not permissible to install daemon processes through the official program). Relocatable is set up to run at 10-minute intervals and gather location data in the background. This means location data is typically available to the browser on a jailbroken phone without having to launch the Locatable app proper. Several of you have asked if there's a way to do a scheduled publish of your location to a destination server of your choice based on the data that Relocatable collects. The answer is a definite yes, and Mike Carambat emailed me the following solution:
Requirements 1. Jailbroken iPhone 2. Install "Locatable" from Cydia 3. Make sure you have "SQLLite" from Cydia 4. Make sure you have "cURL" from Cydia 5. A server based facility to store the data captured from your phone Concept Basically, "Locatable" is a springboard app which uses Core Location to capture GPS coordinates. The cool thing about it, is that it stores them in a SQLite database which is then easily accessible. You query this database via the sqlite3 command and pipe its results to cURL which forwards the data to your server. Instructions 1. Create a shell script called "pushgps" on your iphone which you will invoke on a periodic basis. Put it in the /usr/bin/ on your iphone. This shell script looks like this: ---------- start ---------- #! /bin/sh curl -d POS="`sqlite3 /var/mobile/Library/WebKit/Databases/http_lbs.tralfamadore.com_0/*.db 'select latitude, longitude from location where tag = "Current"'`" ----------- end ----------- (replace the "yourserverhere" and "path_to_gps_recorder" with YOUR server and recording software. (see below for ideas on doing this) Don't forget to: chmod 755 pushgps 2. Next, create a plist file /System/Library/LaunchDaemons/com.whatever.pushgps.plist which contains: ---------- start ---------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""> <plist version="1.0"> <dict> <key>Label</key> <string>com.whatever.pushgps</string> <key>ProgramArguments</key> <array> <string>/usr/bin/pushgps</string> </array> <key>StartInterval</key> <integer>600</integer> </dict> </plist> ----------- end ----------- (replace the "whatever"s with your name, company name, domain, or whatever. This is just an identifier. the 600 refers to every 10 minutes. change if needed. Locatable's interval defaults to 10 minutes, but can be changed as well in its plist file (same directory)) 3. Create software to record the GPS data You'll need to post the coordinate data to *somewhere* online. No, I'm not gonna do it for you. Get your own server ;) Maybe the folks at would be open at some point to do this for us. I wrote a simple perl script called which runs on my server which simply records and time/date stamps the data. Something like this: ---------- start ----------
#!/usr/bin/perl # GPS Recorder $maxhistory=1000; # Total number of locations to store if ($ENV{"REQUEST_METHOD"} eq 'GET') {$buffer=$ENV{"QUERY_STRING"};} else {read (STDIN, $buffer, $ENV{"CONTENT_LENGTH"});} @vars=split(/&/,$buffer); foreach $var (@vars) { ($name, $value)=split (/=/,$var); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; chomp($name); chomp($value); $stuff{$name}=$value; } if (exists ($stuff{'POS'})) { ($lat,$long)=split(/\|/,$stuff{'POS'}); chomp($lat); chomp($long); &GetDateTime; open (STUFF, "gpslocation.txt"); @lines=; close (STUFF); $numlines=@lines; $sp=0; if (($numlines-$maxhistory)>-1) { $sp=$numlines-$maxhistory; } open (STUFF, ">gpslocation.txt"); for ($i=$sp; $i<$numlines; $i++) { chomp($lines[$i]);
print STUFF "$lines[$i]\n";
} print STUFF "$date\t$time\t$lat\t$long\n"; close (STUFF); print "Content-type: text/plain\n\n"; print "Latitude: $lat\n"; print "Longitude: $long\n"; exit(0); } print "Content-type: text/plain\n\n"; print "ERROR"; exit(0); sub GetDateTime { ($second, $minute, $hour, $dayofmonth, $month, $year, $weekday, $dayofyear, $isdst) = localtime(time); $year=($year+1900); $month++; $date=sprintf("%02D",$month)."/".sprintf("%02D",$dayofmonth)."/".sprintf("%04D",$year); $time=sprintf("%02D",$hour).":".sprintf("%02D",$minute).":".sprintf("%02D",$second); }
----------- end -----------
Thanks Mike! Update (1 Sep 08): While this method still works (and it provides a good example of a server-side script to handle the data), as of version 0.3 Relocatable allows you to specify a command to execute each time a location fix is acquired, so there's no need to use the pushgps part. See this post for details.

Labels: , , , , ,

Copyright (C) 2001-2008