Introduction
Reverse GeoCoding translates map coordinates (latitude, longitude) to a physical street address. A reverse geocoder application can be designed in minutes using GeoBase, and with just a few lines of code. To demonstrate GeoBase's ease of use, we'll create a simple reverse geocoder with three text boxes and a search button (see figure 1).

Figure 1 - Basic reverse geocoder
By adding two extra lines of code, and a map control, we can provide a visual indication of the search results (see figure 2).
.png)
Figure 2 - Reverse geocoder with map control
Note: If you do not have the GeoBase SDK, then click here to download a 30 day trial now.
The Design Overview
In GeoBase, reverse geocoding is achieved with the 'GeoCoder.ReverseGeoCode()' method. It accepts a LatLon (a latitude/longitude pair, expressed in degrees) and returns an Address. An Address may contain such information as street number, street name, city, county and state.
In this tutorial, when the user has input the values for latitude and longitude, and pressed the 'Search' button, we'll perform three operations:
- Create a LatLon from the input string
- Retrieve the address by reverse geocoding the LatLon
- Display the address in the address textbox
Once that is up and working, we'll then add a map control to the application, and when we get a search result, we'll zoom the map to the returned address.
The Reverse GeoCode Application
Step 1
Start up a new Visual Studio project, and add C:\Program Files\Telogis\GeoBase\bin\geobase.net.dll as a reference. If you are using Visual Studio 2010 or later, make sure the target framework is the full .NET framework and not a Client Profile.
Step 2
In the design view, create your form to look similar to that of figure 3.

Figure 3 - Basic reverse geocoder control layout
Name the controls as follows:
- search button - buttonSearch
- address output text box - textBoxAddress
- latitude input text box - textBoxLat
- longitude input text box - textBoxLon
Step 3
In code view, add the following 'using' statement to Form1.cs:
using Telogis.GeoBase;
Step 4
Create a 'click' event handler for the search button, and add the following code (the comments explain the functionality):
private void buttonSearch_Click(object sender, EventArgs e)
{
Address myAddress;
LatLon myLatLon;
double myLat, myLon;
textBoxAddress.Clear();
//Create LatLon from input text boxes
myLat = double.Parse(textBoxLat.Text);
myLon = double.Parse(textBoxLon.Text);
myLatLon = new LatLon(myLat, myLon);
//Get address by reverse geocoding LatLon
myAddress = GeoCoder.ReverseGeoCode(myLatLon);
//Display address
if (myAddress != null)
textBoxAddress.Text = myAddress.ToString();
else
textBoxAddress.Text = "No Address Found";
}
Step 5
Run your application. Enter the latitude and logitude values, and press the search button.
Step 6
Go back to the design view, and add a map control as shown in figure 4. Rename the map control 'mapMain'.

Figure 4 - Reverse geocoder final layout
Step 7
Return to the code view, and in the buttonSearch event handler, add the following two lines at the end, just under the "//Display address" section:
//Center the map to the lat/lon, and zoom map to street level mapMain.Center = myLatLon; mapMain.Zoom = ZoomLevel.StreetLevel;
Step 8
Run and test your application.
Conclusion
Within a few minutes, a couple of controls and just a few lines of code, we have created a complete and fully-functional reverse geocoder using GeoBase.
Published, Jun 20th 2010, 20:02
Tagged under: dotnet geobase forward geocoding reverse geocoding maps
