{ End Bracket }

Matrimony mashup

Michael Richter

Code download available at:WeddingVEAddIn2007_10.exe(338 KB)

In my job as Web site manager for MSDN® Magazine and TechNet Magazine, I often have to decide whether to do some mind-numbing manual work that might take several days or try to write an application to do it all for me. Of course, writing that application might take several days in itself, so the time/cost benefit of automation is not always realized. Still, building the application keeps me happy and engaged with my work, whereas repetitive manual tasks can make me hate my job.

I am getting married in October, and I decided to apply my developer skills to automating some of the wedding-planning tasks—which can be equally mind-numbing (but don't tell my fiancée I said that). Luckily for me, she's handling most of the plans, but she did ask me to do two things: create the wedding Web site and manage the guest list.

  (Click the image for a larger view)

Instead of typing in directions and static map links, I created a dynamic page with the Virtual Earth™ API (see msdn.microsoft.com/msdnmag/issues/06/09/EarthlyDelights). I populated two dropdown lists with addresses from an XML file and used one list as a starting route point and the other as the destination route point. Each control has an onchange event that detects if both route points are set and sends the addresses to the GetRoute method of my VEMap object. This updates the map and displays the directions between the points.

This worked fine when I was plotting a route between two addresses, but I also wanted the ability to plot routes between specific longitude and latitude coordinates and between coordinates and addresses. Well, my simple page to automate the maps and directions quickly became complex.

I tried sending coordinates as strings to GetRoute because that is how addresses are sent, but I discovered that coordinates have to be sent as VELatLong objects. I ended up putting a flag in the value for coordinates on the list to clue the JavaScript into creating a new VELatLong for the route point:

<option value="821 Stewart Avenue, Garden City, NY">Wingate Hotel</option> <option value="POSITION,40.729877,-74.038788">Holland Tunnel</option> <option value="POSITION,40.60294,-74.066305">Verazzano Bridge</option>

My JavaScript code is able to detect if the route point is a set of coordinates by the POSITION flag and send a VELatLong object to GetRoute instead of a string.

I also wanted to see all the guests' addresses on a map. It would be helpful to see which guests would be coming from far away and thus needing a hotel room. It would also be great to see which guests might be able to carpool. And of course, it would be very cool to show the map on our Web site.

I decided to use Virtual Earth pushpins, but I didn't have coordinates for any of the addresses. The VEMap object has a Find method in version 5 of the Virtual Earth control that you can supply with an address and it will return coordinates to a callback function (the name of the callback is passed into the Find method as a parameter). This is great if you need to find one address, but what if you need to find 150? I realized too late that the problem with calling the Find method 150 times is that each call to the callback method overwrites the previous call. So, you cannot use the Find method to get coordinates for many different addresses on one map, at least not in rapid succession.

So I used a geocoding Web service. Microsoft provides the MapPoint® Web service, which offers many features, including one that does exactly what I want (msdn2.microsoft.com/bb545004).

Instead of building this map on a Web page, I chose to build it inside Microsoft® Excel. Inspired by Josh Trupin's Geopegging article (see )msdn.microsoft.com/msdnmag/issues/07/04/EndBracket), I used Visual Studio® Tools for Office 2nd Edition to host a Web-browser control inside an Excel 2007 custom pane. When I select a group of cells, my add-in detects if any addresses are present and, if so, it shows a map of the addresses in the Web browser control. This way, I can add different addresses to Excel or highlight several addresses and see them on a map instantly. You can download the final solution from the MSDN Magazine Web site.

I think most developers will agree that it is fun to automate a job even if performing it manually might be quicker. It's more satisfying to get all the work done by just pushing a button in your custom application. In the case of my wedding, I took some potentially boring tasks and had fun with them. It made me happy, but it made my fiancée happy, too, and that's what's really important.

Michael Richter is the Web Site Manager for MSDN Magazine and TechNet Magazine. He lives in New York City.