Example 8 - Reading and writing GPS data
Example 8a - Read out GPS:
Task:
Read out GPS signal and process it further.
Solution:
gps = $'GPS.Location';
gpsInfo = sFormat("Lat: %.8f °N, Lon: %.8f °E, Alt: %.1f m", gps[0], gps[1], gps[2]);
Functions used:
Explanation:
gps
: The result variablegps
is a vector with 3 elements that can be indexed using the [...] syntax. Here,gps[0]
is the latitude,gps[1]
the longitude andgps[2]
the altitude.
For the general use of vectors, please refer to these sections of the online documentation:
Example 8b - Write GPS:
Task:
Build a Gps variable in the smartCORE from individual channels for latitude and longitude (or altitude), which can then be used in the usual places (OSF, optiCloud, geoFence, etc.).
Solution
latitude = 49.89367167;
longitude = 8.82370667;
gpsDieburg = [latitude, longitude, 140.0]; // Order [<lat>, <lon>, <alt>]
gpsBlurred = [0.01 * round(gps[0] * 100), 0.01 * round(gps[1] * 100), 0.0];
Functions used:
Explanation:
- To build a Gps variable in smartCORE, a 3-component vector must be constructed using the [...] syntax as above:
- The local variables latitude and longitude can of course be derived from calculations, a table or the original GPS position.
info
If no data type "gpsLocation" is available in optiCONTROL, make sure that you are using the latest version of optiCONTROL.