Explore Videos MSDN eNews Social
Windows
Web
Phone
Cloud
Visual Studio
Security
ALM
Breakpoint
Canada Does Windows Azure
More
The latest on developer tools and technologies you care about.

Sign Up
Latest Editions
Previous Editions  
Stay connected through on your favourite social network.

Twitter
Facebook
LinkedIn

Windows Phone App Challenge #2: Area Gas Prices

Windows Phone App Challenge #2: Area Gas Prices

  • Comments 1

app challenge - area gas prices

Last night, while picking up a Windows Phone that I’d loaned to a developer for the weekend so he could give his app a proper test on a real device instead of the emulator, I decided to fill up the gas tank on the Deathmobile, named after the car in the movie that inspired my academic career – Animal House.

(Yeah, it’s 12 years old, but with only 110,000 km on it – living in the city, doing lots of bike commuting and living right by a subway station has a lot to do with the low mileage.)

The gas station was in Vaughan, a suburb just north of Toronto, and regular gasoline sold for CAD$1.05 a litre (for my American readers, that’s USD$3.91 a gallon). As I got closer to home, I noticed that the gas stations were charging CAD$1.00 a litre, or USD$3.72 a gallon. I’d pumped 40 litres of fuel into my car, and had I waited until I got closer to home, I could’ve saved two dollars. For me and this one instance, that’s a minor loss, especially since I only have to fill my tank once every two or three weeks. For someone who does a daily commute, that sort of savings adds up.

However, this incident gave me an idea, and hey, two bucks is a small price to pay for inspiration. How about a phone app that lets you know whether you’re getting a good deal at the gas station?

Gas Price Sites

There are sites like GasBuddy.com, a network of just under 200 city-specific sites that track gas prices. According to their registration page, gas prices vary by 10 – 15 cents a litre (30 – 50 cents a gallon) within a city. The site boasts a membership of 700,000 people sharing gas prices in their area and acting as gas price data collectors and reporters. Each GasBuddy city’s site displays the latest prices reported for that city, along with the handle of the member who posted the price.

Here’s a screenshot of the Toronto-specific GasBuddy site, TorontoGasPrices.com:

torontogasprices site

It’s one thing to cruise this site on a nice big monitor at home or a laptop or even a netbook. On a phone, it’s a bit of a challenge to read:

torontogasprices wp7

Yes, I know you can always use pinch zoom, but then you’re making the user do a lot of scrolling and paging, just to get an answer to a simple yes/no question: Am I getting a good deal at this gas station?

A mobile app that answers this question should adopt the Windows Phone 7 design philosophy of “Glance and Go”. It should give you the answer in a form like this:

gas app example

Getting the Info

For the app to work, you’ll need at least two pieces of information:

  • The area where the user is located
  • Gas prices for that area

Ideally, you’ll want to use GPS for getting the user’s location. You can access the GPS on Windows Phone 7 through the Location service, which lives in the System.Device.Location namespace. There’s pretty good coverage of it in the documentation, and I’ll post some code examples in a later article. You may also give the user the user the option of looking at gas prices in other cities, especially nearby ones.

Getting the gas prices for a specific area is a little trickier. You have a couple of options, listed in order from most to least feasible or realistic:

  1. Get the gas prices from an XML feed. Parsing it is the easy part – the XElement class of the System.XML.Linq namespace makes it pretty easy. Examples abound all over the ‘net – check out Scott Guthrie’s really simple WP7 Twitter app code for an example, and I’ll post an example in a later article.

    As for the feeds themselves, I know that GasTicker.com provides feeds for a number of North American cities. I have no idea how accurate they are – you may have to do a little field research, comparing their reported prices to actual prices in your town.
  2. Scrape the gas prices from a site that publishes them. Once again, the technical part is easy – the DownloadString method of the WebClient class in the System.Net namespace, given an URI (in either string or URI object form), returns a string containing whatever’s there. Once you’ve got the string, it’s up to you to apply whatever string-crunching magic you want to extract the gas price information from it.

    The trickier part is whether the site from which you’re scraping the prices minds. These sites often make their money from ads, and by scraping, you’re effectively bypassing them. Perhaps you can work out a deal with a site, but if you’re doing that, they might be able to give you the data in a more convenient form like an XML feed, and then you can go to method 1.
  3. Have an army of volunteers watch gas stations all over a given area like a hawk. They can then feed the data into some central repository – perhaps an XML feed that they update – and your app can retrieve that data as needed. You can scale this down and even go “hyperlocal” by focusing only on gas stations in your neighbourhood or even just one gas station.

There’s your challenge. I’ll write a follow-up article with example code, but in the meantime, fire up Visual Studio and get on it! If you write an app and submit it to Marketplace, drop me a line and let me know.

Previous App Challenges

pomodoro timer

This is the second in a series of Windows Phone 7 App Challenges, in which I present ideas for apps for Windows Phone 7 developers.

In the previous installment in this series, I presented users with the idea to write a timer that people could use for the Pomodoro Technique, a very simple but very effective method to boost your personal productivity. You can read more about it (and see some code, too) here.

This article also appears in Global Nerdy.

Leave a Comment
  • Please add 8 and 4 and type the answer here:
  • Post
  • Tip: To make your life much easier, if you can get an RSS/ATOM Feed you can use the System.ServiceModel.Syndication assembly from Silverlight 3.  It is much quicker to parse a formatted document than brute forcing some XML. I'm using it in my Polymorphic Podcast App and it seems to be working great.

Page 1 of 1 (1 items)