Introduction:
Geocoder.us offers a free (for non-commercial use) web service that may be used to geocode physical addresses. The details of the service and usage terms may be located at: http://geocoder.us/. In general, the Geocoding service is based upon the use of Tiger/Line data gathered by the US Census bureau. Geocoding is defined as the process of estimating the latitude and longitude of a physical address. Naturally the service is based upon physical addresses so its use is limited to tagging physical addresses with a lat/long. Also, since this is based upon US Census Bureau data, only US addresses can be geocoded using the service.
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.
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 navigation device.
The demonstration application will evoke the web service to find the coordinates for a physical address and will display the best result along with any other addresses that match the search criteria. In Figure 1, note that the search term, "100 Peachtree, Atlanta, GA" was sent to the service; the best result is displayed in the "Best Match" group and all matches are displayed in the "All Possible Matches" group box. Since "Peachtree" is a very common name for a street in Atlanta where it is apparently the civic pastime to name streets "Peachtree", the data grid view control contained in the "All Possible Matches" group is pretty full.
Figure 1: The demonstration application running
Figure 2: Displaying the coordinates in Yahoo Maps
Getting 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) along with a web reference pointing to http://rpc.geocoder.us/dist/eg/clients/GeoCoder.wsdl
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;
The imports are per the default configuration for a Windows application.
Following the imports, the namespace and class are defined and a default constructor added.
namespace FreeAddressGeocoder
{
public partial class Form1 : Form
{
/// <summary>
/// Default constructor
/// </summary>
public Form1()
{
InitializeComponent();
}
Next up is the button click event handler used to evoke the Geocoding web service; the code is annotated to describe what is going on within the event handler.
/// <summary>
/// Geocode the address using the GeoCode Service
/// from geocoder.us
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGeocode_Click(object sender, EventArgs e)
{
// make sure there is an address
// to geocode
if (txtSearchAddress.Text == string.Empty)
{
MessageBox.Show("Invalid search address.", "Error");
return;
}
try
{
// instance the geocoder service
us.geocoder.rpc.GeoCode_Service gcAddress = new us.geocoder.rpc.GeoCode_Service();
// the event handler for completion of the geocoding
// does the work of displaying the results; the site offers
// alternative methods for viewing the geocoding results
gcAddress.geocode_addressCompleted += new us.geocoder.rpc.geocode_addressCompletedEventHandler(GetLatLong);
// call the asynchronous version of the geocoder
gcAddress.geocode_addressAsync(txtSearchAddress.Text);
// dispose of the service instance
gcAddress.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Geocoding Error");
}
}
}
/// <summary>
/// Get the geocoding service results and display them
/// to the user
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GetLatLong(object sender, us.geocoder.rpc.geocode_addressCompletedEventArgs e)
{
try
{
// the address is broken up into parts so
// reassemble them into a street address using
// only the parts that have been populated
// by the service
// start with the street number
txtStreet.Text = e.Result[0].number.ToString() + " ";
// add the prefix (e.g., N, SE, etc.)
if (e.Result[0].prefix.ToString() != string.Empty)
txtStreet.Text += e.Result[0].prefix.ToString() + " ";

Joe LeporePosted Jan 4, 2012, 7:09 PM
This code no longer seems to be working. Did an update of the web service file as well. Never get any results back from the web service.
s kPosted Feb 25, 2008, 11:42 AM
can you guys please help, is there any free webservice to convert lat long to osgridref.