|
Download the Eye4Software GPS Toolkit fully functional 30 day trial version for free |
|
Browse through the Eye4Software GPS Toolkit manual |
Yes, it is possible to do high precision distance calculations using the GPS Toolkit. Instead of the Great Circle formula, it uses Vincenty's formula which far more accurate.
The function to calculate the distance takes the source and destination coordinates in latitude / longitude format. If your position is in Northing / Easting, you have to convert it to WGS84 first. Below you can find the sample code to calculate distance:
' This demo shows how to calculate the distance between two WGS84 coordinates ' and how to use the ConvertUnits functions to convert this distance to various distance units like miles and feet. ' For more information on how to use the Eye4Software GPS Toolkit with VBScript, ' visit http://www.eye4software.com/products/gpstoolkit/source#vbscript Option Explicit Dim objUtilities, objConstants Dim srcLatitude Dim srcLongitude Dim dstLatitude Dim dstLongitude Dim dblDistance srcLatitude = 51.90 srcLongitude = 4.24 dstLatitude = 51.89 dstLongitude = 4.93 dblDistance = 0.00 ' Create intance of GpsUtilities object Set objUtilities = CreateObject ( "Eye4Software.GpsUtilities" ) ' Create instance of GpsConstants object (distance units) Set objConstants = CreateObject ( "Eye4Software.GpsConstants" ) WScript.Echo "Eye4Software GPS Toolkit " & objUtilities.Version & " - Distance and Units Demo" WScript.Echo ' Calculate Distance, Azimuth and Reverse Azimuth dblDistance = objUtilities.CalculateDistance ( srcLatitude, srcLongitude, dstLatitude, dstLongitude ) WScript.Echo "Result = " & objUtilities.LastErrorDescription WScript.Echo WScript.Echo "Distance (m) = " & FormatNumber ( dblDistance, 2, 0, 0, 0 ) WScript.Echo "Distance (km) = " & FormatNumber ( objUtilities.ConvertUnits ( objConstants.GPS_PROJECTION_UNITS_M, objConstants.GPS_PROJECTION_UNITS_KM, dblDistance ), 2, 0, 0, 0 ) WScript.Echo "Distance (miles) = " & FormatNumber ( objUtilities.ConvertUnits ( objConstants.GPS_PROJECTION_UNITS_M, objConstants.GPS_PROJECTION_UNITS_MI, dblDistance ), 2, 0, 0, 0 ) WScript.Echo "Distance (NM) = " & FormatNumber ( objUtilities.ConvertUnits ( objConstants.GPS_PROJECTION_UNITS_M, objConstants.GPS_PROJECTION_UNITS_NM, dblDistance ), 2, 0, 0, 0 ) WScript.Echo "Distance (feet) = " & FormatNumber ( objUtilities.ConvertUnits ( objConstants.GPS_PROJECTION_UNITS_M, objConstants.GPS_PROJECTION_UNITS_FT, dblDistance ), 0, 0, 0, 0 ) WScript.Echo WScript.Echo "Azimuth = " & FormatNumber ( objUtilities.CalculateAzimuth ( srcLatitude, srcLongitude, dstLatitude, dstLongitude ), 1, 0, 0, 0 ) WScript.Echo "Azimuth (rev) = " & FormatNumber ( objUtilities.CalculateAzimuth ( dstLatitude, dstLongitude, srcLatitude, srcLongitude ), 1, 0, 0, 0 ) WScript.Echo WScript.Echo "Ready."