Convert GPS coordinates from one map datum to another using Visual Basic

Download Eye4Software GPS Toolkit free trial Download the Eye4Software GPS Toolkit fully functional 30 day trial version for free
Download Eye4Software Coordinate GPS Toolkit Manual Download Eye4Software GPS Toolkit Manual
Browse through the Eye4Software GPS Toolkit for Windows manual Browse through the Eye4Software GPS Toolkit manual

Introduction

The Eye4Software GPS toolkit allows software developers to add GPS functionality to their own programs without the need to have any knowledge on serial communications and GPS protocols like RS-232 and NMEA0183.

The product can be used in many programming environments, such as Visual Basic, Visual C++, Visual Studio.Net, Borland C++ Builder, Borland Delphi and VBA, but also web oriented applications such as ASP, ASP.NET and PHP, and all other programming environments that support ActiveX.

Prerequisites

First you must have Visual Basic and the Eye4Software GPS Component installed on your computer. We will use Visual Basic 6.0 in this document, but other versions from 6.0 and up can be used. You can download the Eye4Software GPS Component here.

Creating the project

Start the Visual Basic IDE, and select the "New Project" option from the "File" menu. The "New Project" dialog now appears, select the "Standard EXE" option to generate a Windows GUI application.

Performing geodetic datum transformations using Visual Basic

Add a reference to the ActiveX component

In order to declare and create the objects from your Visual Basic application, you need to add a reference to the ActiveX object, by choosing the "References" option from the "Project" menu. A list of components installed on the system is displayed. Just check the checkbox in front of the "Eye4Software GPS Toolkit 3.0" and click "OK".

Performing geodetic datum transformations using Visual Basic

Declare and create the object(s)

After adding the reference to the control, you can declare the objects like this:

Private objProjection As GpsProjection
Private objDatumDst As GpsDatumParameters
Private objDatumSrc As GpsDatumParameters

The objects can be created in your code by double clicking on the Form you created, this will open the Form_Load handler. Paste the following code in this function:

Set objProjection = CreateObject("Eye4Software.GpsProjection")
Set objDatumSrc   = CreateObject("Eye4Software.GpsDatumParameters")
Set objDatumDst   = CreateObject("Eye4Software.GpsDatumParameters")

The source code

The source code below demonstrates how to build a very simple datum transformation program using VB. The software reads the source latitude and longitude from two edit boxes, performs a datum transformation, and displays the result. To modify the code to use another source or destination map datum, please have a look at the map datum list.

Option Explicit

'/////////////////////////////////////////////////////////////////////////

Private objProjection As GpsProjection
Private objDatumSrc As GpsDatumParameters
Private objDatumDst As GpsDatumParameters

'/////////////////////////////////////////////////////////////////////////

Private Sub CommandTranslate_Click()

    ' Set Source Datum ( WGS84 )
    ' The ID for WGS84 is 4326, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums 
    ' To convert from another datum, just change the code below (EPSG code)
    objDatumSrc.LoadFromId(4326)

    ' Set Destination Datum ( NAD27 )
    ' The ID for NAD27 is 4267, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums 
    ' To convert to another datum, just change the code below (EPSG code)
    objDatumDst.LoadFromId(4267)
    
    ' Set Source coordinates
    objProjection.Latitude = CDbl(TextLat1.Text)
    objProjection.Longitude = CDbl(TextLon1.Text)

    ' Perform the datum transformation
    objProjection.TransformDatum objDatumSrc, objDatumDst

    ' Display the result
    TextLat2.Text = objProjection.Latitude
    TextLon2.Text = objProjection.Longitude    
End Sub

'/////////////////////////////////////////////////////////////////////////

Private Sub Form_Load()
    ' Create the objects
    Set objProjection = CreateObject("Eye4Software.GpsProjection")
    Set objDatumSrc = CreateObject("Eye4Software.GpsDatumParameters")
    Set objDatumDst = CreateObject("Eye4Software.GpsDatumParameters")
      
    ' Set default values for input boxes
    TextLat1.Text = "33.59"
    TextLon1.Text = "-112.15"
End Sub

'/////////////////////////////////////////////////////////////////////////