Requires Google Earth to be installed and the default program when a KML file is opened.
Procedure Name | Type | Description |
(Declarations) | Declarations | Declarations and private variables for the CGoogleEarthPoints class. |
LineWidth | Property | Line width of lines. |
Class_Initialize | Initialize | Set initial parameters for the class. |
AddIconStyle | Method | Add an icon to the style in order to reference it as a point and display it rather than the default pin. |
DescriptionAdvanced | Method | Create a description with HTML styles, graphics, and hyperlinks. This can then be passed as the Description to the creation of the point. |
AddPoint | Method | Add a placemark based on latitude and longitude to the collection of points to put into the KML file. |
AddAddress | Method | Add a placemark based on an address location to the collection of points to put into the KML file. This can be used rather than providing the latitude and longitude in the AddPoint procedure. Note that the point coordinates are used by Google Earth to include in the default view. Use the LatitudeLongitudeFromAddress function from modGoogleMapsAPI module to get GPS coordinates. |
AddLine | Method | Add a placemark for a line segment to a KML file. |
ExtendLine | Method | Extend a previously created line segment from the location of the last AddLine or ExtendLine method call. |
Save | Method | Complete the KML file and save the final changes. This method must be called before launching the KML file in Google Earth. |
GetFileName | Private | Get the file name with extension without the leading drive and folder names. This private member supports the class. |
StylesColor | Private | Create the styles section to support every color for line segment. It uses the line width specified in the Create method for all the lines. |
ColorToStyle | Private | Helper function to translate color enum value into the selected KML line style. These styles are defined in StylesColor. |
CreateKMLFile | Private | Create and saves a Google Earth KML file from a string. |
KillFile | Private | Delete the named file, handling errors if the file does not exist. |
LaunchKML | Method | When the file is created, launch Google Earth with the KML file that was created. The user must have KML files associated with Google Earth for this feature to work. |
Launch | Private | Open Google Earth by specifying the path to the KML document we created. |
' Example of CGoogleEarthPoints ' ' To use this example, create a new module and paste this code into it. ' Two procedures are avaialble. ' Run either of the procedures by putting the cursor in the procedure and pressing: ' F5 to run it, or ' F8 to step through it line-by-line (see the Debug menu for more options) ' See what happens in Google Earth. Google Earth must already be installed on your PC to run this. Private Const mcstrKMLFile As String = "C:\Total Visual SourceBook 2013\Samples\GoogleEarth.kml" Private Sub Example_CGoogleEarthPoints() ' Comments: Example of using the CGoogleEarthPoints class to create a KML file to display points and lines on Google Earth with VBA and VB6. ' Requires Google Earth to be installed and the default program when a KML file is opened. Dim clsGoogleEarthPoints As CGoogleEarthPoints Dim strError As String Set clsGoogleEarthPoints = New CGoogleEarthPoints With clsGoogleEarthPoints ' Override default line width from 2 to 5 .LineWidth = 5 ' Add points using coordinates. Note that the description may contains HTML formatting including in-line formatting and hyperlinks ' Location of FMS offices Call .AddPoint("FMS Office", "8150 Leesburg Pike, Suite 1150, Vienna, VA 22182
http://www.fmsinc.com", 38.916376, -77.226722) ' Add White House Call .AddPoint("White House", "1600 Pennsylvania Ave, NW, Washington, DC", 38.897683, -77.036497) ' Add another location based on its name/address rather than GPS coordinates Call .AddAddress("US Capitol", "US Capitol building
http://www.congress.gov", "US Capitol") ' Draw line from FMS to White House Call .AddLine(-77.226722, 38.916376, -77.036497, 38.897683, eKMLColorYellow) ' ----------------------------------------------------------------------------------------- ' These are the original borders of the District of Columbia, not the current borders. ' Territory south of the Potomac river is part of Virginia. ' Draw 2 specific line segments for the NE and SE border of Washington DC Call .AddLine(-77.041283, 38.995077, -76.909618, 38.892674, eKMLColorBlue) ' DC NorthEast Call .AddLine(-76.909618, 38.892674, -77.029953, 38.79813, eKMLColorRed) ' DC SouthEast ' Instead of creating new segments for the other (original) borders of DC, just extend the line from the previous point Call .ExtendLine(-77.171938, 38.89318, eKMLColorGreen) ' DC SouthWest Call .ExtendLine(-77.041283, 38.995077, eKMLColorOrange) ' DC NorthWest ' ----------------------------------------------------------------------------------------- ' Save the KML file strError = .Save(mcstrKMLFile) If strError = "" Then ' Launch Google Earth with the KML file strError = .LaunchKML End If If strError <> "" Then MsgBox strError End If End With End Sub Private Sub Example_CGoogleEarthKMLFileAdvanced() ' Comments: Example of using the CGoogleEarthPoints class to create a KML file to display multiple points with advanced descriptions when you click on it. ' The descriptions include logos and hyperlinks and can be customized further with HTML standard syntax. Dim clsGoogleEarthPoints As CGoogleEarthPoints Dim strDesc As String Dim strError As String Set clsGoogleEarthPoints = New CGoogleEarthPoints ' Use a combination of points and addresses to show locations. ' Note that the AddPoint rather than AddAddress procedure should be used for your extreme points since that's what Google Earth uses to set its perspective. ' In this example, it's used for the most West and East points. For other data, you may need to use your most North and South locations. With clsGoogleEarthPoints ' =============== ' Show the FMS location with a logo and custom HTML detail screen: ' Add a style icon for the FMS logo .AddIconStyle "FMSlogo", "http://www.fmsinc.com/AboutUs/fms_logo.jpg" ' Get the KML formmated description for FMS strDesc = .DescriptionAdvanced("FMS Office", _ "We are located here. Click on the logo to load our web page.", _ "http://www.fmsinc.com/AboutUs/fms_logo.jpg", _ "FMS HQ", _ "http://www.fmsinc.com") ' Add a point using the FMS icon Call .AddPoint("FMS Headquarters", strDesc, 38.916376, -77.226722, "#FMSlogo") 'Call .AddAddress("FMS Headquarters", strDesc, "8150 Leesburg Pike, Vienna, VA 22182", "#FMSlogo") ' =============== ' Show the National Archives with a picture and custom HTML detail screen containing its logo with a hyperlink ' Add a style icon for a picture of the National Archives headquarters .AddIconStyle "NationalArchivesPic", "http://fmsinc.com/Consulting/government/national-archives_dc.jpg" ' Get the KML formmated description for the National Archives strDesc = .DescriptionAdvanced("National Archives", _ "The United States National Archives is a client of FMS. Click on the logo for more information.", _ "http://www.fmsinc.com/Consulting/government/national-archives.jpg", _ "National Archives on the National Mall", _ "http://fmsinc.com/Consulting/government/national-archives.aspx") ' Add a point using the National Archives icon Call .AddPoint("National Archives", strDesc, 38.8927573, -77.022956, "#NationalArchivesPic") 'Call .AddAddress("National Archives", strDesc, "National Archives, Washington, DC", "#NationalArchivesPic") ' =============== ' Show the Pan American Health Organization HQ with their logo and custom HTML detail screen containing its logo with a hyperlink ' Add a style icon for a logo of PAHO .AddIconStyle "PAHOlogo", "http://www.fmsinc.com/Consulting/img/PAHO.JPG" ' Get the KML formmated description for the National Archives strDesc = .DescriptionAdvanced("Pan American Health Organization Headquarters", _ "The Pan American Health Organization is a client of FMS. Click on the logo for more information.", _ "http://www.fmsinc.com/Consulting/img/PAHO.JPG", _ "PAHO HQ", _ "http://www.fmsinc.com/Consulting/portfolio/logistics-support-system.aspx") ' Add a point using the PAHO icon Call .AddAddress("Pan American Health Organization", strDesc, "525 23rd Street, NW, Washington, DC 20037", "#PAHOlogo") ' =============== ' Show the George Washington University with their logo and custom HTML detail screen containing its logo with a hyperlink ' Add a style icon for a logo of George Washington University .AddIconStyle "GWUlogo", "http://www.fmsinc.com/Consulting/graphics/GWUlogo.jpg" ' Get the KML formmated description for George Washington University strDesc = .DescriptionAdvanced("George Washington University", _ "George Washington University is one of many education institutions that are clients of FMS. Click on the logo for more information.", _ "http://www.fmsinc.com/Consulting/graphics/GWUlogo.jpg", _ "George Washington University", _ "http://www.fmsinc.com/Consulting/education-systems.aspx") ' Add a point using the GWU icon Call .AddAddress("George Washington University", strDesc, "George Washington University, Washington, DC", "#GWUlogo") ' =============== ' Save the KML file strError = .Save(mcstrKMLFile) If strError = "" Then ' Launch Google Earth with the KML file strError = .LaunchKML End If If strError <> "" Then MsgBox strError End If End With End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP