Waypoint Importer For MapPoint
In this article, Rahn Lieberman shows how to import an XML file containing waypoint information into MapPoint 2002 as Pushpins
Introduction
Geocaching is a high-tech treasure hunt. You’re given the longitude and latitude of a cache, and try to find it using a GPS unit. One Web site for the sport is at www.geocaching.com, where a listing of geocaches is available, along with additional information.
The process of entering the coordinates of a cache into your GPS can be fairly tedious. EasyGPS (www.easygps.com) has developed a means of downloading a list of caches. Using the EasyGPS software, you can easily sort and transfer waypoints and geocaches to your GPS.
A shortcoming of the EasyGPS software is that it does not provide any mapping capability to use with the waypoints. With this COM Add-In, you can import all of the waypoints in an EasyGPS file into MapPoint as Pushpins.
This article will discuss the file format of the EasyGPS .loc file, building a COM Add-In and GUI to point to the file, and using the MSXML 3.0 object to read the file.
Requirements
I developed the program in Visual Basic 6 (SP3) on Windows XP Professional. MapPoint 2002 is required.
The EasyGPS File
On www.Geocaching.com, you can download any geocache as an EasyGPS file. You do not need EasyGPS installed on your computer.
An EasyGPS file downloads with a .loc extension by default. Opening it up in your favorite text editor reveals that it is in fact XML. I’ll use the following sample file (and call it the loc file from here on out.):
There are a few general routines for housekeeping:
CancelButton_Click hides the Add-In, effectively closing it
cmdBrowse_Click brings up the common dialog open window when the browse button is clicked. A filter is set to show loc files (*.loc), XML files (*.xml) or all (*.*) files.
txtPath_Change sets the common dialog filename property so it points to the correct file if the path is manually entered into the text box txtPath
The function MakeDecDeg converts decimal degrees into degree decimal minutes.
The sub cmdImport_Click is the workhorse of the program.
The first lines are variable declarations. Notice we declare some XML document variables for the XML parser. We also declare some MapPoint variables.
The following lines setup our XML document object and load the loc file. This is all that is required! No messing with input or get statements, which is one of the big bonuses of using the MSXML object.
'initialize XML doc
Set xDoc = New MSXML2.DOMDocument
xDoc.Load (CommonDialog1.FileName)
Next we connect to the current map using the following code. :
'initialize MapPoint app
Set mpApp = g_oApp 'New MapPoint.Application
Set mpMap = mpApp.ActiveMap
mpApp.Visible = True
mpApp.UserControl = True
Now, make sure the XML document contains some nodes by counting the number of children in the root node. If it is 0, then there is nothing in the file to look at. Note there are a few fancy error- trapping methods of the MSXML object that could be used to validate the XML.
lRecordCount = xDoc.documentElement.childNodes.Length
If lRecordCount > 0 Then
Now the code loops through the XML document and grabs the next waypoint node. The following lines read each waypoint and assign the values to variables:
Since we know the format of the node, we can point to the specific children nodes to grab the information we want and assign it to variables.
For example, the name of the waypoint is in the “name” child node, which will always be the 1st child node of the waypoint. The waypoint ID is always an attribute of this node.
The following code inserts a Pushpin into the MapPoint map and formats the heading:
The Pushpin’s location is set by a call to GetLocation, using the latitude and longitude of the waypoint. The name of the waypoint is put into the Pushpin’s heading. The coordinates are added based on the user’s preferred style. It also puts in the link to the Web page.
For easy visibility, set the Pushpin symbol to a big red dot (a built in type). An improvement to the program would be to let the user chose the Pushpin symbol.
Lastly, the Pushpin balloon state is set based on the user’s preference and the map is moved to the Pushpin location.
To complete the project, compile the DLL and open MapPoint. On the Tools menu, choose COM Add-Ins, click Add, and then click your new DLL. You should now have the Waypoint importer on your Add-In menu, ready for use.
Discuss this story in the forum.
Author: Rahn Lieberman
Email: rahn(AT)theliebermans.com
URL: http://www.theliebermans.com
Rahn is a software tester in the Seattle, Washington area. His computer interests include databases, programming and GIS applications. When not sitting in front of the computer, he enjoys rock climbing, mountain biking and running, all which combine nicely with geocaching. He recently completed a lifetime goal of running a marathon, and is more than happy to tell anyone that pauses long enough to listen about it.