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!

23 December 2008

Turf Bombing on your iPhone

The creator of Turf Bombing emailed to let me know this creative web application now supports iPhones with Locatable installed. This is a great concept that blends real locations with a virtual game that can be played on both laptops and mobiles. (And you'll probably have an advantage playing on an iPhone with GPS, as WiFi-based locations are often far less accurate.)

Here's a brief description of the concept:

Turf Bombing is a location-based turf battle game which rewards and encourages traveling and learning about different neighborhoods.
Gangs are assigned by the zip code of your home address. The goal of each gang is to gain as much territory as possible.
Territories are acquired as players plant time bombs at different locations in physical space. If the bomb is not diffused by a local gang member in time, the bomb will explode and the territory will be turned over to the gang that planted the bomb.

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 BaseX.be 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.

01 September 2008

Locatable roadmap and feature planning

I thought I'd give an update on where I'm going with Locatable and I'd love to hear feedback or suggestions for new functionality.
I've just tested a better technique for saving data to the client-side database from the Locatable application which means that the app itself should not need any network connectivity. This is good news as there's a risk of settings becoming unsynchronized between the app and the database the way it's working right now (e.g. if the connection fails). This means rewriting all the preferences-saving and preferences-loading code and won't have any visible effect on the UI.
Preferences anyway are about to get more complex. Now that Locatable is tracking per-site preferences (so you can choose to only be prompted once or twice per site to share location), there needs to be a UI to see what sites are currently in the list and manage their individual settings. I'm thinking of it a lot like the cookie manager in Firefox — you should be able to blacklist and whitelist individual sites that you visit, as well as alter their settings individually. So that's the task for Locatable 0.4.
The other item on the TODO list requires a schema upgrade, which is why I've been procrastinating on it. It would be good to store the horizontal accuracy of the reading so this can be shared (via the W3C API and redirector). It would be nice to have altitude and vertical accuracy as well, though I'm not sure if these even work (certainly not on an iPod Touch!).
Once those are in there, the plan is to submit to the AppStore. If accepted, the only difference between the jailbroken version and the AppStore one will be the inclusion of Relocatable, which of course won't work. (I won't be discontinuing development on it, but it may become its own package in Cydia.)
In the meantime I'm open to suggestions on other functionality that should be included. Primarily what I've been hearing about is people using Relocatable to do their own lojack-type apps. I'd really like to get some feedback on using Locatable on your web sites to integrate positioning data, do maps mash-ups, and so on. Private feedback is fine, public is even better (and I'll be happy to put links on the Featured Sites page).

28 August 2008

The W3C Geolocation API on iPhone with Locatable

I've ported the W3C's draft Geolocation API so it can be used from an iPhone with Locatable installed (my Javascript skills are far from elite, but with enough prodding and old-school alert() debugging, I got there). This means that in addition to the redirect API (which is nice for embedding static links to pages that can take lat/long coordinates), you can now get at location information on demand via Javascript, through what is likely to become the standard API in future browsers.
To use it, just include this in your HEAD:

You can download and install the script locally if you like (but please check back for new versions from time to time).
Then, to use it, just use the standard W3C-prescribed approach via a global object called Locatable, e.g.

The only addition to the W3C API is an isEnabled() method. This will attempt to figure out if the API will work on the current browser. Right now this merely checks if someone is on an iPhoneOS device, but might be more sophisticated in the future.
There's a test page up at http://www.tralfamadore.com/test-w3c.html that demonstrates this functionality.
Some implementation notes:

The same logic applies when sharing location as with the redirector. Depending on user preferences, an alert will ask them to confirm if they want to share their location. If they decline, you'll get an error callback if you provide the second argument to getCurrentPosition.

If the location needs to be refreshed, the app will launch, update the reading, and then return to Safari. This can take some time (in Locatable 0.3, up to 20 seconds, depending on the user accuracy setting). On jailbroken phones with default Locatable settings this is unlikely to occur as the daemon will be updating location in the background, but an AppStore version will not have this advantage, so be mindful of this.

W3C PositionOptions (the accuracy hint) does nothing at the moment.

watchPosition() is "implemented" (that is, the function exists), but you'll only ever get one reading, so it's not entirely useful.

The accuracy reading in the position object is currently the user-set minimum accuracy level (a round number like 10, 100, or 1000 meters), not the device-reported accuracy of the reading itself. This is likely to change in future versions.

Altitude and velocity are not implemented yet and yield null values.

w3c-api.js will attempt to detect if you're running an iPhone or iPod Touch and not install itself otherwise. It also won't overwrite navigator.geolocation if it's already implemented (non-null).

It probably goes without saying, but you should include the w3c-api.js script on every page you want to use it in.

I'd consider this a beta version — I've done some basic testing but haven't tried too many use cases. Let me know how it works for you in the comments.
Update (31 Aug 08): Upon some reflection, I decided it's best not to try to automatically install as the navigator.geolocation global, so the script has been updated to use a global called Locatable (capital L) instead. You're free to assign it to navigator yourself (i.e. navigator.geolocation = Locatable). Also added the isEnabled() method.

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

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:

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:

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:

24 August 2008

Locatable: Some stats

Locatable has been on Cydia for about a week now, and thanks to BigBoss I can see that there have been over 5,000 downloads (some of these are people upgrading from 0.1 to 0.2, of course).
I've also done some analysis of the visitors to the Featured Sites page. First of all, I'm impressed by how far around the globe the jailbroken iPhone has traveled. Within just the last 12 hours there have been visitors from over 50 countries -- here are the top ones:
1. U.S. (18%)
2. France (7%)
3. Mexico (7%)
4. Brazil (6%)
5. U.K. (6%)
6. Spain (4%)
7. Canada (4%)
8. Slovakia (3%)
9. Italy (3%)
10. Norway (3%)
Traffic is overwhelmingly (95%) coming from iPhones as opposed to iPods Touch, as you might expect for an app that is most useful with GPS when you're out and about; on the other hand, so far usage is still fairly evenly split between WiFi and mobile networks.
In other news: I've got a heavily reworked version of Relocatable just about ready to go that makes it very easy to do the location tracking hack posted previously. It also does a far better job of getting accurate GPS readings, though it takes a little longer. I'm working on incorporating the same technique into Locatable and I'd like to start adding some more management preferences, such as the ability to have trusted sites that you aren't continually prompted for (much the same as the way the iPhone works for applications that request to read your location: after a couple of checks, it assumes you're fine with it). If you have other feature ideas please comment!
n.b. If you have a working iphone-gcc toolchain installed, the Makefiles are set up so you can build your own copies of Locatable and Relocatable from source now, and the changes mentioned above for Relocatable are checked in.

19 August 2008

Locatable 0.2 + source release

Locatable 0.2 should be out on Cydia soon. Release early, release often, as they say. It's a minor release that fixes an issue and adds a feature:

Locatable and its daemon process (Relocatable) would get stuck if the device couldn't get a location fix. Now it dies gracefully (though this can take a few seconds).

New option in preferences panel to specify how accurate of a location reading to get.

I'll also be adding some more options to the redirector, including the ability to test for a Locatable-enabled device without needing to prompt the user to share location. Stay tuned and your feedback is welcome.
Also, in the practicing-what-you-preach department, the Locatable and Relocatable applications are available in source form under the GPL in the svn.tralfamadore.com repository. To check them out using Subversion, try svn co http://svn.tralfamadore.com/repos/iphone/locatable (or relocatable). I'm not exactly proud yet of my Objective-C skills, so your critiques are probably warranted and indeed you're welcome to contribute!

18 August 2008

Howto: Developing with the Locatable redirect service

For the first release of Locatable I've stuck to a very basic HTTP (REST) API. The idea is that you have a page that can take latitude/longitude coordinates in its URL. This might be an existing page, or it might be an iPhone-specific entry page that sets up some other variables or session cookies or whatever you might want to do.
Template URLs
The basic URL to perform a redirect to your location-enabled page is as follows:
http://lbs.tralfamadore.com/r?u={myURL}
For this to work, {myURL} needs to be a full absolute URL (including http://) to your page.
Locatable looks for some special sequences in the URL you provide.
@lat@ will get replaced with the user's latitude, as a floating point number
@long@ will get replaced with the user's longitude, as a floating point number
If the user hasn't installed Locatable, they choose not to send their location to your site, or the mobile device can't read an accurate location, the template parameters will be replaced by the empty string (that is, they will be stripped out of the URL before the redirect occurs). You should code your page for this condition. (Note: I'm looking at adding a parameter so you can check whether the service is enabled to make it easier to detect when you'll have a valid location, but that's not there yet; see below for a way to set a default value.)
To take an example, the Geocaching web site expects a URL that looks like this:
http://www.geocaching.com/seek/nearest.aspx?origin_lat=39.549167&origin_long=-94.329722&dist=100
To make this into a template URL for Locatable, we simply replace the numbers with the macros described above:
http://www.geocaching.com/seek/nearest.aspx?origin_lat=@lat@&origin_long=@long@&dist=100Encoding the URL
Because we're going to use it as a querystring parameter to the redirector, make sure to properly encode your templated URL. Here's how to do it in various languages:

PHP: urlencode($myURL)

Java: java.net.URLEncoder.encode(myURL, "UTF-8")

Javascript: encodeURIComponent(myURL)

You get the basic idea. There's also a little encoder you can cut and paste from on this page.
After doing that step on our example URL, it looks like this:
http%3A%2F%2Fwww.geocaching.com%2Fseek%2Fnearest.aspx%3Forigin_lat%3D%40lat%40%26origin_long%3D%40long%40%26dist%3D100
Then we just need to add this to the redirector URL, and we're off and running:
http://lbs.tralfamadore.com/r?u=http%3A%2F%2Fwww.geocaching.com%2Fseek%2Fnearest.aspx%3Forigin_lat%3D%40lat%40%26origin_long%3D%40long%40%26dist%3D100
Take that URL, put it in a HTML href, and you're ready to go!
Defaulting the Location
If you'd rather have some value for latitude and longitude rather than none, you can use the following syntax:
@lat:defaultValue@ gets replaced by the latitude, or defaultValue if none is available
@long:defaultValue@ gets replaced by the longitude, or defaultValue if none is available
For example, if we were to start with the same Geocaching URL, but want to default to Charing Cross in London (latitude 51.509, longitude -0.125), we'd use the following template URL:
http://www.geocaching.com/seek/nearest.aspx?origin_lat=@lat:51.509@&origin_long=@long:-0.125@&dist=100
Happy (geo)hacking!

Geohacking with Locatable

Locatable has had well over a thousand downloads in the first 12 hours, so I've just been updating the featured sites to give everyone something to play with. I haven't yet heard of any "made for iPhone" sites that can take advantage of the latitude/longitude sharing feature of lbs.tralfamadore.com, so for now the links you'll find there are publicly available web sites and services that take lat/long coordinates.
I used some of the more common online mapping services to test during development, but now that I have a little more time to browse around, I'm finding a lot of interesting things that can be done already:

Geocaching. Use your iPhone to participate in local treasure hunts.

GeoNames. Find and identify nearby landmarks.

Panoramio. Look at photos that have been taken near your location.

Here are some things I'd love to see but haven't tracked down yet (even if they don't yet exist as lat/long-enabled URLs, the mashup would be easy to do): movie listings, traffic reports, friend finder, turn-by-turn spoken driving directions, emergency services finder, shop finder (Apple store, anyone?), and so on.
Maybe I'll hunt around a little later. In the meantime, let me know if you have any links to post.

17 August 2008

Locatable 0.1

Locatable 0.1 is out on Cydia! If you have a jailbroken 2.0 iPhone, you'll find it in the Utilities section of Cydia. For more info, check lbs.tralfamadore.com.
I wanted to take a minute to give a quick thank you to some of the people and resources that have helped me get this up and running.

Jay Freeman, a.k.a. saurik, who has built and written more and better software for iPhone development than possibly the collective staff at Apple.

BigBoss, for hosting the package gratis -- many thanks and highly recommended!

The community at iPhoneDevSDK who post tons of useful examples and answers to coding questions.

15 August 2008

Sneak peek

I'm close to a beta release for Locatable, and I'm excited enough about it that I wanted to give a quick preview, from a tech-centric point of view.
Locatable is an application and geolocation federation service that let you share your location (GPS coordinates, or any decent facsimile thereof) from your iPhone or iPod Touch to any web site, via the built-in Safari browser. It takes advantage of the new client-side storage capabilities of Safari to allow some very nice anonymity and privacy features -- notably, the user's location is never stored on the server side, with the service at lbs.tralfamadore.com acting as a gateway to storage on the device.
There's a lot to say about this and its relationship to similar services such as MyLoki (Skyhook) and FireEagle (Yahoo!). Both of those could be integrated, as can just about any existing location-based service.
Anyway, check out the concept and check back for more updates soon.