
This tutorial will demonstrate the fundamentals of implementing GPS functionality in BrightBuilder and how to incorporate this functionality into your application.
Scanning through BrightBuilder and BrightForms is handled by the GPS object, which can be found in the data source tree under Objects > GPS.
Opening and closing the GPS on a device can be done in two different ways, the simplest using the Microsoft Intermediate GPS driver. To do this, we use the method that can be found under the data source tree - GPS.OpenIntermediate(). For non-compatible devices, The GPS.Open() method can be used to specify the port parameters to use. Please consult the Bright Software Object Definitions Reference Manual for more information. Closing the GPS device is used with the GPS.Close() method, regardless of the method used to open it.
The methods for opening or closing a GPS returns int values, 0 on success or otherwise specifying the error code. Once opened, subsequent methods can be used to establish valid readings and retrieve the data the GPS device records.
A valid reading from the GPS can be determined via the GPS.HasValidRead() and the GetFixQuality() methods, which return ‘true’ and an int > 0 respectively on a valid read. If there is a valid reading from the GPS, all GPS captured data may be accessed from the device, using the ‘Get’ functions.
An example is as follows:
IF(GPS.HasValidRead() == true AND GPS.GetFixQuality() > 0)
{
sat_field = GPS.GetSatellitesInView();
lat_field = GPS.GetLatitude();
long_field = GPS.GetLongitude();
alt_field = GPS.GetAltitude();
}
ELSE
{
Form.MessageBox("Error", "No valid reading", 0);
}
Depending on the GPS hardware device and satellite visibility, it may take up to a few minutes to get a successful read from a GPS device. Hence, in a typical application, this fragment would usually run in a timed expression set to read from the GPS at a set interval, defined by the form’s ‘Action – Timer’ and ‘Timer Interval’ properties, and stopping when the GetFixQuality() method ==1.
The ‘Get’ methods of the GPS return different types of values, which may be referenced using the Object Definition Reference Manual, the ‘More Info’ option of the context menu, or the help window within BrightBuilder. Despite being different types, all the methods can be loaded into an edit control, or be appended to a string, with exception to the GPS.GetGPSTime() method.

Longitude and Latitude also have two ‘Get’ methods each, for convenience and can be returned as either a string, where direction is represented by the last character (N, S, E or W) or a double, where positive values represent east and north respectively.
Provided that the types captured from the GPS object are the same as the ones defined by the project’s tables, saving and loading the data can be performed by standard database operations. If not, the conversion of values is needed.
This exercise will aim to implement the basic functionality of GPS, and will centre around completing the ‘Locator’ form, shown below.
Complete the open_btn_Click and close_btn_Click expressions. These expressions will attempt to open and close the GPS – if successful; it will notify the user that the GPS has opened/closed, if not; it will display an error message with the appropriate error code. Use the GPS.OpenIntermediate() method to open the GPS.
Complete the getpos_btn_Click function. The expression linked to this button will check if the GPS has a valid reading and fix quality. If it does, it will update the values into the appropriate edit controls, if not, if will update all the controls to say “No Valid Reading Available”. Last_field loads up the date/time of the last GPS read, using the GPS.GetDateTime() method. Be sure to convert the return type of this method to a string.
A possible solution is contained in GPSFinished.bsp.