 |
|
 |
 |
Finding Sites Within a Specified Distance From an Address
This article demonstrates the use of MapPoint's COM add-in capability to display locations from a database within a specified distance from a reference point.
Assumptions:
Note: This code uses MapPoint North America, but it can be easily modified to use fields more appropriate for European addresses.
In your add-in, create a form. Add a combo box called "cmbPushpin". This will be used to list all pushpins in the "My Pushpins" collection on your map.
Create a text box called "txtTolerance" where you will enter the distance around the selected pushpin in which to find addresses. For this example the distance is in miles. Also, add a command button "cmdMap" that will be used to trigger the map creation.
In the Add-in designer procedure fired when the form above will be displayed, add the following code:
You now have a form loaded with a combo box listing any Pushpins that are on the underlying map.
Before going on let me spend a minute on data issues. Unfortunately, MapPoint's ability to handle data is not all that it could be. If you build an ADO recordset, you can't directly import the points into a MapPoint dataset. You can only create pushpins as demonstrated in the code example below. This means that you really only have 2 fields to use for data: Name and Note. The other way to get data in and bring in all desired fields is to use the ImportData method, but with SQL Server that means using a UDL (Universal data link) file and limiting the syntax of how you access SQL Server objects. For example, I don't know how you could use a stored procedure. This is my single biggest gripe with MapPoint. (If I am incorrect about this, someone please set me straight.)
Put the following code behind the "cmdMap" command button. See comments in the code for details of how this works. At a high level, the code determines the latitude and longitude of the selected pushpin, queries the database for points whose latitudes and longitudes are in a rectangle that is slightly larger than the desired radius and uses the MapPoint "Distance" method for each point in the rectangle to determine whether it falls within the desired distance.
To use this:
- Put a pushpin on the map,
- Select the map form from your add-in options,
- Select the desired pushpin and enter the desired distance in the text box,
- Click the map button.
You now have all of the points on your database that are within the specified distance from the reference point. Clearly, additional filtering can be done to limit the displayed data and make this even more useful.
Discuss this story in the forum.
Author: Walt Cygan Email: wcygan(AT)macrogroup.net URL: http://www.macrogroup.net 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.
|
 |
 |
 |
Recent Discussion
|
 |
|
 |
 |
|
 |
Resources
|
 |
|
 |
|
 |