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 and the
accuracy of the data is largely dependent upon the quality of the Census Bureau
data.
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 by mapping it with
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.vb).
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:
Public Class Form1
Public Class Form1
''' <summary>
'''
Default Constructor
''' </summary>
''' <remarks></remarks>
Public Sub New()
'
This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
The next section of the code is used to parse the results returned from the web
service and to display the results to the user in the "Best Match" and "All
Possible Matches" groups. The code is annotated to describe what each part of
the code does.
''' <summary>
''' Use the geocoder.us web service
''' to geocode and address; display both
''' the best matching address along
''' with a collection of all addresses
''' meeting the search criteria
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub GetLatLong(ByVal sender As Object, _ByVal e Asus.geocoder.rpc.geocode_addressCompletedEventArgs)
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 Then
txtStreet.Text += e.Result(0).prefix.ToString() + " "
End If
' add the street name
If e.Result(0).street.ToString() <> String.Empty Then
txtStreet.Text += e.Result(0).street.ToString() + " "
End If
' add the suffix (if any)
If e.Result(0).suffix.ToString() <> String.Empty Then
txtStreet.Text += e.Result(0).suffix.ToString() + " "
End If
'add the street type (e.g., ST, CT, RD, PKWY, etc.)
If e.Result(0).type.ToString() <> String.Empty Then
txtStreet.Text += e.Result(0).type.ToString()
End If
' add the city, state, and zip
txtCity.Text = e.Result(0).city.ToString()
txtState.Text = e.Result(0).state.ToString()
txtZip.Text = e.Result(0).zip.ToString()
' display the latitude and longitude
txtLatitude.Text = e.Result(0).lat.ToString()
txtLongitude.Text = e.Result(0).long.ToString()
' create a datatable to hold any additional
' possible address matches
Dim dt As New DataTable()
' define all of the columns and add them
' to the data table
Dim dcAddress As New DataColumn()
dcAddress.DataType = System.Type.GetType("System.String")
dcAddress.ColumnName = "Address"
dcAddress.Caption = "Address"
dt.Columns.Add(dcAddress)
Dim dcCity As New DataColumn()
dcCity.DataType = System.Type.GetType("System.String")
dcCity.ColumnName = "City"
dcCity.Caption = "City"
dt.Columns.Add(dcCity)
Dim dcState As New DataColumn()
dcState.DataType = System.Type.GetType("System.String")
dcState.ColumnName = "State"
dcState.Caption = "State"
dt.Columns.Add(dcState)
Dim dcZip As New DataColumn()
dcZip.DataType = System.Type.GetType("System.String")
dcZip.ColumnName = "Zip Code"
dcZip.Caption = "Zip"
dt.Columns.Add(dcZip)
Dim dcLat As New DataColumn()
dcLat.DataType = System.Type.GetType("System.String")
dcLat.ColumnName = "Latitude"
dcLat.Caption = "Lat"
dt.Columns.Add(dcLat)
Dim dcLong As New DataColumn()
dcLong.DataType = System.Type.GetType("System.String")
dcLong.ColumnName = "Longitude"
dcLong.Caption = "Lon"
dt.Columns.Add(dcLong)
' create a row
Dim row As DataRow

Join the conversation! Your thoughts help the community grow.