spacer2 1_1 1_2
 The MP2K Update!
Front Cover
What's New
Sample Data
MapPoint 2013
Press Releases
MapPoint Forums
Link to MP2Kmag
Wish List
MapPoint Trial
 Earlier Content
Past News Items
Past What's New Announcements

MapPoint 2013

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials

Map Visitors


Reverse Geocoding, Pt. III

Walt Cygan, a frequent contributor of late, submits this solution for tackling reverse geocoding

My code to do reverse geocoding was intended to answer the need to able to find an address near a location virtually all of the time. Compared with Gilles Kohl's approach in, mine is more brute force in nature. I use the ObjectsFromPoint method repeatedly at slightly different locations to attempt to find an address.

In the code I use data on a SQL Server 2000 database where I have lat and lon stored. The steps I go through to get the address are:

  1. Use the GetLocation method with the database lat and lon.
  2. Check the Location object from step 1 with the ObjectsFromPoint method to see if the best match has a street address. If so, I'm done. If not, move on.
  3. Round the database lat/lon to 4 digits after the decimal and get use those coordinates with GetLocation
  4. Check the Location object from step 3 with the ObjectsFromPoint method to see if the best match has a street address. If so, I'm done. If not, move on.

Now is where the fun starts: I start working outward in squares (spherical rectangles really) each 1-ten thousandth of point of latitude and longitude larger that the one before. The center point is the location found after rounding to 4 digits. The first square has 8 points, the next has 16, then 24, 32, etc. I have the code set to do 10 squares before giving up, giving a total of 442 attempts, including the one with the original latitude and longitude. The idea here was to find the nearest possible address without ever testing the same point twice.

For each point the same process as in steps 1-4 is followed: GetLocation followed by ObjectsFromPoint.

I tested this code on 22 locations in and around Minneapolis and St. Paul, Minnesota. Most of these points had been moved slightly to more accurately place their pushpin on the map before getting their latitudes and longitudes that were stored on the database. Addresses were found for all 22 locations in just over a minute using the ActiveX control in a VB app. The majority of this time was used to find 2 of the addresses, 1 in a more rural area, 1 next to a golf course (therefore fewer available nearby streets and addresses). 10 addresses were found on the first attempt; 18 were found in 7 or fewer attempts; the rest in 18, 39, 112 and 403 attempts. When run only with the 18 addresses that were found in fewer than 10 attempts, the process ran in about 10 seconds.

The code is as follows (Note to folks who saw a preview of this: I made a small change adding "Exit For" statements for each inner loop for the sides of the "squares"):

Discuss this story in the forum.

Author: Walt Cygan
Email: wcygan(AT)
Walt is a consultant for The MACRO GROUP, Inc. in Minneapolis, Minnesota. The MACRO GROUP, Inc. is an information systems consulting firm whose customers include public, private and non-profit organizations of all sizes.

MP2Kmag Internet

 Recent Discussion
Browse GIS books and periodicals
Find a MapPoint Partner or Consultant
Real Estate Columbia MO Homes for Sale

Want Your Site To Appear Here?

   © 1999-2012 MP2K. Questions and comments to:
  Microsoft and MapPoint 2002/2004/2006/2009/2010/2011/2013 are either trademarks or registered trademarks of Microsoft.