VB.NET Get KML File Properties (Google Earth API)

This article explains how to get the different properties from a KML file using VB.Net. Properties such as:

  • Longitude
  • Latitude
  • Altitude
  • Range

Step 1:

The first step would be to add reference to the Microsoft XML library. I have Microsoft XML V6.0 installed on my system. The KML file is basically an XML file, therefore this library will help us get the required data from this XML file:
Reference


Step 2:

As mentioned in the previous section, the KML file is basically an XML file. XML files have Nodes and Child Nodes. In order to get the require data you would need to figure out which node contains the required data. Fortunately I’ve already done that for you in the code below:

Sub main()
Dim dblLongitude As Double
Dim dblLatitude As Double
Dim dblAltitude As Double
Dim dblHeading As Double
Dim dblTilt As Double
Dim dblrange As Double
Dim objXML As MSXML2.DOMDocument60
Dim objNode As MSXML2.IXMLDOMNode

objXML = New MSXML2.DOMDocument60
'load the KML File
objXML.Load ("D:StuffBusinessTempLocation.KML")
'get the node with the required data
objNode = objXML.ChildNodes.Item(1).ChildNodes.Item( _
0).ChildNodes.Item(4).ChildNodes.Item(1)
'get the required data
dblLongitude = objNode.ChildNodes.Item(0).Text
dblLatitude = objNode.ChildNodes.Item(1).Text
dblAltitude = objNode.ChildNodes.Item(2).Text
dblHeading = objNode.ChildNodes.Item(3).Text
dblTilt = objNode.ChildNodes.Item(4).Text
dblrange = objNode.ChildNodes.Item(5).Text
End Sub

The Longitude, Latitude, Altitude, … values are stored in the variables dblLongitude, dblLatitude, dblAltitude.

You can download the file and code used in this article from the link below:

Leave a Reply

Your email address will not be published. Required fields are marked *