- Implementing the GPS management
- Checking whether the GPS is enabled
- Be notified when the GPS status changes
- Position tracking
- Ending the use of GPS functions
- Implementing geolocation tracking
- Principle and implementation
- Operation according to the mode of use of the application
- When to use each function?
- Functions available according to the platforms
- Summary table
Managing geolocation and GPS
WINDEV Mobile and WEBDEV allow you to exploit geolocation and GPS features found on mobile devices and browsers.
Implementing the GPS management
Checking whether the GPS is enabled
To check whether the GPS is enabled, all you have to do is use GPSStatus
// Is the GPS enabled?
IF GPSStatus() = gpsEnabled THEN
Error("The GPS cannot operate.", ...
"It must be enabled to access this application.")
Be notified when the GPS status changes
To be notified when the GPS status changes, simply call GPSStatus
and specify the name of the procedure that will handle the current GPS status.
The procedure code is as follows:
IF CurrentStatus = Status THEN RETURN
CurrentStatus = Status
// The provider was enabled by the user.
STC_Status = "GPS enabled"
// The provider was disabled by the user.
STC_Status = "GPS disabled"
// The provider is off service.
STC_Status = "GPS off service"
// The provider is temporarily unavailable.
STC_Status = "GPS unavailable"
// The provider is available.
STC_Status = "GPS available"
// Requests location tracking with a maximum time between two calls to
// GPSFollowMovement(_GetLocation, 1000)
In this procedure, if GPS is enabled, a specific procedure is used to track the device.
To track the device's location, simply use GPSFollowMovement
and specify the name of the procedure that will handle location changes.
The code of the procedure can be as follows:
// Update the information about the location
// Latitude and longitude
STC_Latitude = StringBuild("Latitude: %1", MyLocation.Latitude)
STC_Longitude = StringBuild("Longitude: %1", MyLocation.Longitude)
IF MyLocation.SpeedValid = True THEN
STC_Speed = StringBuild("Speed: %1 m/s", MyLocation.Speed)
IMG_SPEED_VALIDITY = IMG_OK
STC_Speed = "Speed: N/A"
IMG_SPEED_VALIDITY = IMG_NOTOK
IF MyLocation.AltitudeValid = True THEN
STC_Altitude = StringBuild("Altitude: %1 m", MyLocation.Altitude)
IMG_ALTITUDE_VALIDITY = IMG_OK
STC_Altitude = "Altitude: N/A"
IMG_ALTITUDE_VALIDITY = IMG_NOTOK
IF MyLocation.DirectionValid = True THEN
STC_Direction = StringBuild("Direction: %1 ° E", MyLocation.Direction)
IMG_DIRECTION_VALIDITY = IMG_OK
STC_Direction = "Direction: N/A"
IMG_DIRECTION_VALIDITY = IMG_NOTOK
STC_Last_update = StringBuild("Last update on %1 at %2.", ...
STC_Last_update.Visible = True
In this code, MyLocation
is a geoPosition
variable. The properties of this type of variable are used to find out the location characteristics.
Ending the use of GPS functions
Depending on the selected settings and on the call frequency, geolocation functions can consume a lot of resources on the device (battery, bandwidth, etc.). GPSEnd
must be called when the location functions are no longer used by the application.
Implementing geolocation tracking
On a mobile device, you may need to track the user's location even when the application is closed or in the background.
You should be able to set up tracking while using as little resources as possible, especially when it comes to battery. This can be achieved by reducing accuracy, compared to standard GPS tracking.
Principle and implementation
To manage location tracking:
- Enable location tracking with geoTrackingEnable.
- Define the procedure called when changing the location with geoTrackingProcedure. This function must be used in the initialization process of project.
Operation according to the mode of use of the application
If the application is already running
, the procedure given to geoTrackingProcedure
is automatically called when a location event is received. Any operation of application can be performed in this procedure.
When the application is stopped
, if a location event is received, the application is restarted in the background. The "Initializing" event of the project is run, then the procedure specified in geoTrackingProcedure
Reminder: To determine if the application has been started in the background
, use ExeInfo
with the exeLaunch
constant. The exeGeoTracking
constant will be returned if the application was started in the background.
When to use each function?
|Function||When to use it? ||Accuracy||Energy consumption|
|geoTrackingXXX||Permanent tracking of location changes, even when the application is in the background.||High accuracy, but the frequency of notifications is low and varies depending on the system. ||Low|
|GPSFollowMovement||Permanent tracking of location changes when the application is in the foreground.||Accuracy according to GPSInitParameter. ||Consumption according to GPSInitParameter.|
|GPSDetectPosition||Notification of the proximity of a given location when the application is in the foreground. ||Accuracy according to GPSInitParameter. ||Consumption according to GPSInitParameter.|
|GPSGetPosition||Get current location at a specific moment when the application is in the foreground. It may take long, depending on the surroundings (inside a building, cloudy day, etc.).||Accuracy according to GPSInitParameter. ||Depends on the number of calls. |
|GPSLastPosition||Immediately get the last known location of the device.||Low consumption, since it depends on when the last location was actually retrieved. Also depends on GPSInitParameter. ||Low consumption. |
Functions available according to the platforms
The table below presents the different geolocation/GPS functions and the different platforms for which they are currently available (this table can evolve with each version):
Cross-platform examples (WINDEV Mobile): WM Geolocation
This page is also available for…