|
|
|
|
|
- Overview
- 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
- Overview
- 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. Example:
IF GPSStatus() <> gpsEnabled THEN
Error("Le GPS n'est pas en état de fonctionner.", ...
"Veuillez l'activer pour avoir accès à cette application.")
EndProgram()
END
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. Example: GPSStatus(_ChangementEtatGPS)
The procedure code is as follows: PROCEDURE _ChangementEtatGPS(Etat)
IF EtatActuel = Etat THEN RETURN
EtatActuel = Etat
EndTimerSys(TIMER_RECUPERATION)
SWITCH Etat
CASE gpsEnabled
LIB_Etat = "GPS activé"
CASE gpsDisabled
LIB_Etat = "GPS désactivé"
CASE gpsOffService
LIB_Etat = "GPS hors-service"
CASE gpsUnavailable
LIB_Etat = "GPS indisponible"
CASE gpsAvailable
LIB_Etat = "GPS disponible"
OTHER CASE
END
In this procedure, if GPS is enabled, a specific procedure is used to track the device.
Position tracking To track the device's location, simply use GPSFollowMovement and specify the name of the procedure that will handle location changes. Example: GPSFollowMovement(_RécupèrePosition, 1000)
The code of the procedure can be as follows: PROCEDURE _GetLocation(MyLocation)
LIB_Latitude = StringBuild("Latitude: %1", MaPosition.Latitude)
LIB_Longitude = StringBuild("Longitude: %1", MaPosition.Longitude)
IF MyLocation.SpeedValid = True THEN
LIB_Vitesse = StringBuild("Speed: %1 m/s", MaPosition.Vitesse)
IMG_SPEED_VALIDITY = IMG_OK
ELSE
LIB_Vitesse = "Speed: N/A"
IMG_SPEED_VALIDITY = IMG_NOTOK
END
IF MyLocation.AltitudeValid = True THEN
LIB_ZOrder = StringBuild("ZOrder: %1 m", MaPosition.ZOrder)
IMG_ALTITUDE_VALIDITY = IMG_OK
ELSE
LIB_ZOrder = "ZOrder: N/A"
IMG_ALTITUDE_VALIDITY = IMG_NOTOK
END
IF MyLocation.DirectionValid = True THEN
LIB_Direction = StringBuild("Direction: %1 ° E", MaPosition.Direction)
IMG_DIRECTION_VALIDITY = IMG_OK
ELSE
LIB_Direction = "Direction: N/A"
IMG_DIRECTION_VALIDITY = IMG_NOTOK
END
STC_Last_update = StringBuild("Last update on %1 at %2.", ...
DateToString(MyLocation.MeasurementDate.Date), ...
TimeToString(MyLocation.MeasurementDate.Time))
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. 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 Summary table 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):
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|