Click here to Skip to main content
12,827,242 members (42,905 online)
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 27 Mar 2009

Reverse Geocoding with C# and MapPoint 2009

, 27 Mar 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Use C# and MapPoint 2009 to find a street address from a latitude/longitude.


This article demonstrates using C# and MapPoint 2009 to look up a street address from a latitude/longitude. MapPoint does not use a Web Service. All data is stored locally, on the user's machine. From my research, MapPoint provides the most economical solution to perform a reverse geocode locally. Libraries from vendors such as ThinkGeo or GeoFrameworks cost upwards of $3000 while MapPoint costs $300.


You can download the MapPoint North America 2009 trial from The download is a whopping 1.2GB, because it contains all of the geographic information for North America.

MapPoint does not include .NET assemblies, and can only be interfaced through COM. If you are my age (26), you may not have much experience using COM. The Windows SDK includes a tool called tlbimp.exe to generate a .NET assembly from a COM Type Library. The assembly, Interop.MapPoint.dll, is included in the code download, and you can generate it yourself with the command:

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\tlbimp.exe" 
 "C:\Program Files\Microsoft MapPoint 2009\MPNA83.tlb" /out:c:\Interop.MapPoint.dll

For more information on COM, I recommend

Using the code

The method Map.ObjectsFromPoint(int x, int y) queries MapPoint for objects at a given latitude/longitude. This method returns street addresses, countries, restaurants, and anything else in the MapPoint database. We implement the method:

private StreetAddress LookupStreetAddress(Location loc)
    FindResults arr = _map.ObjectsFromPoint(_map.LocationToX(loc), _map.LocationToY(loc));
    return arr.OfType<location>().Where(o => o.StreetAddress 
       != null).Select(o => o.StreetAddress).FirstOrDefault();

to cull the results for a street address. If location does not touch a street, it is unlikely that a street address will be returned. MapPoint does not include a method to find the nearest street address.

Our algorithm for GetNearestAddress

Streets seem to be around .0001 degrees in width, so our algorithm uses a grid of points .0001 degrees apart. We iterate through the points, from closest to farthest from the starting location, calling LookupStreetAddress on each point until a match is found.

public StreetAddress GetNearestAddress(double lat, double lon)
    if (lat == double.NaN || lon == double.NaN)
        return null;

    // MapPoint needs to be centered
    _map.GoToLatLong(lat, lon, 1);

    // Zoom level seems to affect what is returned...
    // haven't figured out the pattern here
    for (int i = 0; i < 10; i++)

    // make 10 squares around, each .0001 degrees apart
    StreetAddress addr;
    for (int i = 0; i < 10; i++)
        foreach (Location loc in GetPointsAround(lat, lon, i, .0001))
            if ((addr = LookupStreetAddress(loc)) != null)
                return addr;

    return null;

And there you have it. I have used this with a GPS device and was able to accurately see my current address.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Walter Diego Luque30-Sep-10 10:21
memberWalter Diego Luque30-Sep-10 10:21 
GeneralI use SQL 2005 to find near address Pin
x89327-Mar-09 16:53
memberx89327-Mar-09 16:53 
Generalfree Pin
radioman.lt27-Mar-09 2:55
memberradioman.lt27-Mar-09 2:55 
GeneralRe: free Pin
Richard Marsden27-Mar-09 4:46
memberRichard Marsden27-Mar-09 4:46 
GeneralRe: free Pin
radioman.lt27-Mar-09 5:28
memberradioman.lt27-Mar-09 5:28 
GeneralRe: free Pin
Frank Meffert27-Mar-09 8:25
memberFrank Meffert27-Mar-09 8:25 
GeneralRe: free Pin
james.wren27-Mar-09 8:49
memberjames.wren27-Mar-09 8:49 
GeneralRe: free Pin
Frank Meffert27-Mar-09 10:38
memberFrank Meffert27-Mar-09 10:38 
GeneralRe: free Pin
Stefano Straus25-Apr-09 23:01
memberStefano Straus25-Apr-09 23:01 
GeneralRe: free Pin
Frank Meffert27-Apr-09 6:39
memberFrank Meffert27-Apr-09 6:39 
GeneralFree but against the Google API terms Re: free Pin
Member 888754525-Apr-12 22:47
memberMember 888754525-Apr-12 22:47 
GeneralRe: free Pin
james.wren27-Mar-09 8:55
memberjames.wren27-Mar-09 8:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 27 Mar 2009
Article Copyright 2009 by james.wren
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid