Introduction:
Yahoo Web Services are made available to developers through Yahoo's Developer Network; a variety of services are available but this article is specifically interested in using Yahoo's Geocoding Service. This service will return the closest matching address to a submitted physical address and will also return the addresses position in latitude and longitude. The terms and conditions for using the service are pretty simple; users are permitted to geocode up to 5,000 addresses per day for the very reasonable price of absolutely nothing.
This article will demonstrate the basics of submitting an address to the service, recovering and displaying the geocoded result, and will also demonstrate a simple approach to displaying the location as mapped using Yahoo maps. For more information regarding the program refer directly the Yahoo Developer Network website located at http://developer.yahoo.com/dotnet/.
On a limited basis, the service can be used to obtain and store latitude and longitude on all of the addresses contained in some sort of contact database or asset location database, or might be useful for storing waypoints in a GPS device. Naturally the service is based upon physical addresses so its use is limited to tagging physical addresses with a lat/long.
When visiting the site, take a look at the different programs available and take a look at some of the many services made available through Yahoo.
Figure 1: The demonstration application running 
Figure 2: Displaying the coordinates in Yahoo MapsGetting Started
In order to get started, unzip the included project and open the solution in the Visual Studio 2005 environment. In the solution explorer, you should note these files:
Figure 3: Solution Explorer
The Main Form (Form1.cs)
The main form is the only form contained in the application; all of the application specific code required to access the service, return the results of an address search, and to display those results as text or as a map are included in this class.
The code is pretty simple, if you'd care to open the code view up in the IDE you will see that the code file begins as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
The imports are primarily per the default configuration for a Windows application; the System.Xml library import is the only departure from the default.
Following the imports, the namespace and class are defined and a default constructor added.
namespace YahooGeocoding
{
public partial class Form1 : Form
{
/// <summary>
/// Default constructor
/// </summary>
public Form1()
{
InitializeComponent();
}
Next up is the declaration of a structure used to contain the results returned from a request to geocode a physical address.
/// <summary>
/// Address Struct is used to contain
/// the elements of the geocoded address
/// returned from the Yahoo Map Service
/// </summary>
public struct Address
{
public string Street;
public string City;
public string State;
public string Zip;
public string Country;
public string Lat;
public string Long;
} // declare an address
Address SearchAddress;
The next section of the code is used to request a search on an address; this request is submitted to Yahoo's service which returns the nearest matching address along with its latitude and longitude. The geocoded address returned from the service is stored in an Address.
/// <summary>
/// Call the Yahoo map service to geocode an address and return
/// that address to the caller
/// </summary>
/// <param name="street"></param>
/// <param name="city"></param>
/// <param name="state"></param>
/// <returns>A geocoded address</returns>
private Address GetAddress(string street, string city, string state)
{
Address newAddress = new Address();
// Get XML document
XmlTextReader reader = new XmlTextReader
("http://local.yahooapis.com/MapsService/V1/geocode appid= YahooDemo
&street=" + street + "&city=" + city + "&state=" + state);
// Whitespace
reader.WhitespaceHandling = WhitespaceHandling.Significant;
// Report Node Values
while (reader.Read())
{
if (reader.Name.ToString() == "Address")
newAddress.Street = reader.ReadString().ToString();
if (reader.Name.ToString() == "City")
newAddress.City = reader.ReadString().ToString();
if (reader.Name.ToString() == "State")
newAddress.State = reader.ReadString().ToString();
if (reader.Name.ToString() == "Zip")
newAddress.Zip = reader.ReadString().ToString();
if (reader.Name.ToString() == "Country")
newAddress.Country = reader.ReadString().ToString();
if (reader.Name.ToString() == "Latitude")
newAddress.Lat = reader.ReadString().ToString();
if (reader.Name.ToString() == "Longitude")
newAddress.Long = reader.ReadString().ToString();

Join the conversation! Your thoughts help the community grow.