Brave Location Mobile Apps and Web Solutions

Using Fire Eagle to store your current location

Originally posted on my old MSDN blog

Not that you’d really notice, but I’ve updated the code to show my current location on the map on this blog to use Fire Eagle to store my current location.

If you haven’t heard of it before, Fire Eagle is a service provided by Yahoo! which lets you store your current location, and then allow different applications read or write access that location at an accuracy level that you control.

This is a simple service which is actually really cool, and there are already multiple applications on different platforms (web, client and mobile) which allow you to read and/or update your location dynamically. So if you really want to – and I do! – you can track and expose your location however you want.

The full developer details are at http://fireeagle.yahoo.net/developer (you need a Yahoo! account to access this) so I won’t explain too many of the low-level details here. However here’s a few things to note if you want to investigate yourself:

1. Fire Eagle uses OAuth for securing access to their API, which means:

  • First get the application token by registering your application at Fire Eagle
  • Using the application token you get a request token for an individual user, from which a URL is created to send the user to Fire Eagle to both confirm access permissions to their location for your application, and at the level of accuracy the application may show
  • Once the user has confirmed permission, your application gets a user-specific token which it should store and use to access the Fire Eagle API to get that user’s location

2. There are various libraries available for both OAuth and Fire Eagle access:

  • I used the C# Fire Eagle library at Google Code
  • However there are a couple of bugs in the library that I had to fix:
    • The response can’t be serialised properly because the Error object uses IDictionary which can’t be serialised
    • A couple of the values in the location hierarchy - “exact” and “region” weren’t available
  • Also, the library didn’t expose the latitude and longitude of the locations returned – the main thing I was interested in so I could display the position on my Virtual Earth map!
  • Update (8th Dec 2008) I’ve checked in fixes for both issues and the library extensions I made to the code repository at http://code.google.com/p/fireeaglenet/ If you find any problems, let me know and I’ll take a look ASAP.

 

Once all of the access token details have been obtained and stored in my web.config file (I know, not the most secure practice and not one I’d use on a real production site), then using the C# library it’s very easy to get my location with a few lines of code:

  Token userToken = new Token(appSettings["fireeagle_usertoken"], appSettings["fireeagle_usersecret"]);
  FireEagle fireEagle = new FireEagle(appSettings["fireeagle_consumertoken"], appSettings["fireeagle_consumersecret"], userToken);
  User fireEagleUser = fireEagle.User();
  Location bestLocation = fireEagleUser.LocationHierarchy.BestGuess;

I can then use that Location object (after my extension to the library) to get the latitude and longitude to drive my JavaScript implementation of Virtual Earth shown in an earlier post.

As an aside – which I may come back to in a future post – I wanted to protect some of the pages I built (the ones where I expose my Fire Eagle token details). To do this I used Windows Live ID using code from the Web Authentication SDK – see http://dev.live.com/liveid/ for details.

This was almost trivially easy, and having banged my head against earlier Passport implementations, this was a pleasure to use (if that’s not overstating things!). Kudos to the Live ID team, and if you’ve been put off using WLID after being scarred by previous attempts with Passport, I definitely recommend taking another look.

N.B. This blog post has now moved to https://writingontablets.com