Geeks With Blogs
Bill Osuch - Random geek notes

Yahoo provides their Geocoding Web Service to allow you to find specific latitude and longitude for an address; it's also useful for cleaning addresses where you're not sure of the exact zip code, spelling of the street, etc.

There are actually two web services - the orginal Yahoo Maps Web Service, and the new PlaceFinder service. The original web service has been deprecated, but that's what I'll be demonstrating today; the next post will be about the new PlaceFinder service.

The first step is to obtain a Yahoo! Developer Network ID at:

All of the information on the request parameters and response fields is located at:

You'll send the street, city, state and zip to the API in this format:
(Note, the appid above is Yahoo's demo ID, you can't use it in your code...)

...and get a response back like:
<ResultSet xmlns:xsi="" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps">

-    <Result precision="address">
        <Address>1950 N Stemmons Fwy</Address>



It's incredibly simple to use this via code - just pass the Yahoo Url to an XmlTextReader and parse out the Xml response, like this:

public struct Address
   public string Street;
   public string City;
   public string State;
   public string Zip;
   public string Country;
   public string Lat;
   public string Long;
   public string Precision;

public Address CodeAddresses(string street, string city, string state, string zip)
   string yahooURL = "<your app Id>&street=" + street + "&city=" + city + "&state=" + state + "&zip=" + zip;

   Address SearchAddress = new Address();

   XmlTextReader reader = new XmlTextReader(yahooURL);
   reader.WhitespaceHandling = WhitespaceHandling.Significant;

   while (reader.Read())
      switch (reader.Name.ToString())
         case "Result":
            if (reader.NodeType == XmlNodeType.Element)
               SearchAddress.Precision = reader.GetAttribute("precision");
         case "Address":
            SearchAddress.Street = reader.ReadString().ToString();
         case "City":
            SearchAddress.City = reader.ReadString().ToString();
         case "State":
            SearchAddress.State = reader.ReadString().ToString();
         case "Zip":
            SearchAddress.Zip = reader.ReadString().ToString();
         case "Country":
            SearchAddress.Country = reader.ReadString().ToString();
         case "Latitude":
            SearchAddress.Lat = reader.ReadString().ToString();
         case "Longitude":
            SearchAddress.Long = reader.ReadString().ToString();

     return SearchAddress;

In future posts I'll go over the PlaceFinder service as well as Google's geocoding API.

Technorati Tags:

Posted on Thursday, July 29, 2010 10:10 AM Mapping | Back to top

Comments on this post: Geocoding with the Yahoo Geocoding API

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Bill Osuch | Powered by: