Click to Rate and Give Feedback
Related Articles

Here the author dissects the ASP.NET MVC framework and looks at how controllers work. He then explains how the framework interacts with your controllers and how you can influence those interactions.

Scott Allen

MSDN Magazine May 2009

...

Read more!

This column shows you how to secure the .NET Services Bus and also provides some helper classes and utilities to automate many of the details.

Juval Lowy

MSDN Magazine July 2009

...

Read more!

This article reviews the Prism project developed by the Microsoft patterns & practices group and demonstrates how to apply it to composite Web applications using Silverlight.

Shawn Wildermuth

MSDN Magazine July 2009

...

Read more!

This article describes how to use XHTML and ASP.NET MVC to implement REST services.

Aaron Skonnard

MSDN Magazine July 2009

...

Read more!

Memory usage can have a direct impact on how fast an application executes and thus is important to optimize. In this article we discuss the basics of memory optimization for .NET programs.

Subramanian Ramaswamy and Vance Morrison

MSDN Magazine June 2009

...

Read more!

Also by this Author

Joshua Trupin

MSDN Magazine March 2007

...

Read more!

While spending some idle moments poking around on the Web between working on articles the other day, we ran across a design challenge that Microsoft is co-sponsoring. Along with the IDSA (Industrial Designers Society of America), Microsoft is inviting all you designers out there to draw up plans for the next-generation PC.

Joshua Trupin

MSDN Magazine July 2005

...

Read more!

Joshua Trupin

MSDN Magazine May 2007

...

Read more!

Why we use the paper we do.

Joshua Trupin

MSDN Magazine November 2006

...

Read more!

MSDN Magazine Executive Editor introduces this issue

Joshua Trupin

MSDN Magazine September 2006

...

Read more!

Popular Articles

See how routed events and routed commands in Windows Presentation Foundation form the basis for communication between the parts of your UI.

Brian Noyes

MSDN Magazine September 2008

...

Read more!

Jason Clark

MSDN Magazine July 2003

...

Read more!

Chris Tavares explains how the ASP.NET MVC Framework's Model View Controller pattern helps you build flexible, easily tested Web applications.

Chris Tavares

MSDN Magazine March 2008

...

Read more!

Jeff Prosise explains when it's better to use UpdatePanel and when it's better to use asynchronous calls to WebMethods or page methods instead.

Jeff Prosise

MSDN Magazine June 2007

...

Read more!

When incorporating the ASP.NET DataGrid control into your Web apps, common operations such as paging, sorting, editing, and deleting data require more effort than you might like to expend. But all that is about to change. The GridView control--the successor to the DataGrid-- extends the DataGrid's functionality it in a number of ways. First, it fully supports data source components and can automatically handle data operations, such as paging, sorting, and editing, as long as its bound data source object supports these capabilities. In addition, ...

Read more!

{ End Bracket }
Geopegging
Joshua Trupin

Code download available at: EndBracket2007_04.exe (174 KB)
Browse the Code Online

As part of my birthday haul last year, I received a gem of a gift: a new camera. And not just any camera, either. It was a new Nikon D200.
One of the features that really grabbed my interest was its built-in GPS capabilities. If you had a standard serial-port GPS device, you could plug it into the camera via a converter cable and location data would be written into each shot you took.
The problem was that the serial-port GPS receivers I owned were museum pieces that didn't work with the camera, and new GPS devices tend to have USB connections. Arrgh! I decided to take the most foolhardy plunge since I bought fajitas at a Manhattan street fair two years ago. I created my own homebrew solution out of OEM parts. To make a long story short, it actually worked. If you want the heartstopping play-by-play, you can find it at my blog.
Geopegging Adds GPS Location Data to a JPG(Click the image for a larger view)
I've been putting my photos up on my hosting site, trupin.smugmug.com. Smugmug has a nice feature that automatically maps all your tagged photos, and even though it used Google Earth, I liked it. But I knew I could take this idea a step further. Hundreds, perhaps thousands, of photos could soon be turned from throwaway snapshots into vitally important records of time and place. Adding location data to photos is known as geotagging, but my program would extend that term with a slightly more specific concept, "geopegging."
Geopegging, which is now defined as "adding GPS location data to a JPG through a map-based interface," is a concept that took a few steps to drag into reality. First, I had to figure out where the geo data actually went inside a JPG file. There's surprisingly little information about this online, but I used a variety of sources and the power of the Microsoft® .NET Framework to create a simple EXIF editor. If you want to find the camera's lens aperture at the time of the photo, you look at the field tagged 0x9202. It turns out that the GPS data all goes in tags numbered 0 through 8. This didn't fill me with confidence, because I imagined someone choosing the first numbers they could think of, well after the fact. The Framework includes a GetPropertyItem member in the System.Drawing.Image class, so it's easy to extract header data if you know the EXIF tag value.
Next, I wrote a program that hosted Microsoft Internet Explorer® inside a Windows® Forms app so that I could display Virtual Earth™ and allow a user to select the location to be added to a photo. That was a bit easier. The fun part was getting Virtual Earth working within a frame of my desktop app so that it could communicate back and forth with the Windows Forms code in the app. This part involves a bit of JavaScript inside the window plus some tricks (documented in the Virtual Earth online help) that gets the two parts of the program talking to one another.
The trick here is to wire up the WebBrowser control with some script through its DocumentText property. You use AttachEvent to call a script function when the browser control is clicked; this function then calls window.external.YourFunctionName and passes it a string.
There's more complexity, including handling the Virtual Earth control properly, converting values, and writing to the JPG file. I've put my basic geopegging program up as a download and invite you to take a look at it. Now I've got a world full of tagged photos, and I can update them any time I want. I don't need the homemade GPS device at all...but I still use it, if only to show off a bit.

Joshua Trupin is the Executive Editor of MSDN Magazine and TechNet Magazine.

Page view tracker