When MSN’s Virtual Earth website came online a few months ago, naturally the first thing I did was try it on a Windows Mobile device.  But the website is pretty advanced; it pushes the envelope of what you can do with a pure browser-based app using DHTML, JavaScript, and AJAX.  And, unfortunately, IE Mobile couldn’t render it.  But not being able to access map data on a mobile device just seemed wrong, so I set out to write a Windows Mobile app that could access Virtual Earth’s maps. 

The first step was to figure out how the website worked.  There was no SDK, but viavirtualearth.com had info on how to use VE’s JavaScript control to display a map.  Of course, I already knew that that JavaScript control wouldn’t work on Windows Mobile, but at least now I knew where to find the source code for the control (MapControl.js).  The source code was thankfully not obfuscated, but it didn’t have any whitespace or comments either (presumably to decrease download time).  Now my job basically consisted of adding whitespace to the functions I cared about, and staring at the code until I figured out what it was doing.  And what it was doing was taking four values – latitude, longitude, zoom level, and map type – and encoding them into a URL.  The URL points to a pre-rendered jpeg or png image, called a tile, on the Virtual Earth servers.  (Each tile is 256 pixels square.)  So once I knew that, I knew I didn’t need the JavaScript control at all, I just needed to take those four values, do a bunch of math and transforms to construct a URL, download the URL, and display it.  Then lather, rinse, repeat until I had filled the screen with tiles.  I wrote a C# app to do exactly this, and that’s how Pocket Earth was born.  (I later discovered there already was an app call Pocket Earth, so I renamed my app Virtual Earth Mobile.)

But the Virtual Earth servers can do more than just serve up map tiles; they can also do various flavors of searches.  The simplest search is to search for an address: you take an address string (e.g., “429 Columbus Ave., Boston, MA”) and do an HTTP POST request to and you’ll get back a JavaScript string like “SetViewport(latitude1,longitude1,latitude2,longitude2);”  The four coordinates specify a rectangle on Earth where the address is located.  For a street address, which is essentially a point, a rectangle might not make sense, but if you had searched for, say, “Massachusetts”, you’d definitely need a rectangle.  You might be wondering what the “SetViewport” is for; why not just return four coordinates?  Well, VE’s JavaScript control has a SetViewport function, so you could just have JavaScript evaluate (“eval”) this string, and it would cause the Map Control to display the rectangle specified by the four coordinates.  (Since I don’t have a JavaScript control, my app manually parses out the coordinates.)  There are more details about how to do this kind of search on http://viavirtualearth.com/vve/Articles/3.ashx.

The second kind of search is a search for a business.  Suppose you are looking for restaurants in Boston.  You do the same sort of HTTP POST request to, except now you pass in “Restaurant” and the four lat/long coordinates that bound the area you want to search, and you’ll get back a string containing up to ten search results, each one including the business name, phone number, address, and lat/long.  You also get back a boolean indicating whether there are more search results.  If there are, you can make another request (passing in a different starting index) to get the next batch of ten.  (As with the first kind of search, the string you get back is a JavaScript expression.  Using C#’s RegEx class makes it relatively easy to parse.)

New Windows Mobile 5.0 APIs made it easy to add two features.  The first is “Find a Contact”: pull an address out of your Contacts list and map it.  Using the new ChooseContactDialog() and the WindowsMobile.PocketOutlook.Contact class, this whole feature took ten lines of code.  The second feature is the GPS feature: read your current position from a GPS device and map it.  That was also ten lines of code.  (The GPS classes ship as sample code in the Windows Mobile SDK; they’re not in ROM.)

I said at the beginning that I wrote Virtual Earth Mobile because I wanted to bring map data to mobile devices.  That’s true, but the truth is there were a lot of reasons:

• I wanted to get experience writing a full-fledged managed app. 
• I wanted to dogfood our own development tools, and get some sense of what it’s like to be a Windows Mobile ISV. 
• I thought it would be fun.  I wrote it in my spare time; the running joke was that whenever I came back from vacation the app would have new features.

Having road maps available anytime anywhere is very practical.  Adding satellite/aerial photos isn’t a huge jump in practicality, in my opinion, but the photos certainly are fascinating to look at.   There are all sorts of fun things you can do with them:

• Look at your house from the air. (This is the first thing everyone does.)
• Discover there’s a cemetery you never knew about less than a half mile from the house you grew up in.  (Okay, maybe that’s just me.)
• Check out famous landmarks (Space Needle, St. Louis arch, …)
• Try to find photos where you can make out individual people.
• Quiz your friends to see if they can identify places from the air.  (Here’s one to get you started: http://windowsmobile.members.winisp.net/ve.jpg.)

I’ve always enjoyed looking at maps of unfamiliar places; it’s like taking a virtual tour, and now aerial photos make the tour a little less virtual and a little more real.

The Virtual Earth Mobile app, its help file, and its source code, are all on http://viavirtualearth.com/vemobile.  The app is free, and the source code is under a Shared Source license.  If you want to know more details about how to download images from the Virtual Earth servers, or how to do a search, the source code is the place to go.

 - Jason Fuller