ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Geolocation functions
  • 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
  • When to use each function?
  • Functions available according to the platforms
  • Summary table
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Managing geolocation and GPS
Overview
WINDEV Mobile and WEBDEV allow you to exploit geolocation and GPS features found on mobile devices and browsers.
Universal Windows 10 App In phone applications, you can:
  • Get information about the last known location of the device.
  • Ask to be notified when the device comes near a specific area.
  • Find out the current location of the device.
  • Retrieve an address.
  • ...
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:
// Is the GPS enabled?
IF GPSStatus() = gpsEnabled THEN
Error("The GPS cannot operate.", ...
"It must be enabled to access this 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(_ChangeOfGPSStatus)
The procedure code is as follows:
PROCEDURE _ChangeOfGPSStatus(Status)
 
IF CurrentStatus = Status THEN RETURN
CurrentStatus = Status
EndTimerSys(TIMER_RETRIEVAL)
SWITCH Status
CASE gpsEnabled
// The provider was enabled by the user.
STC_Status = "GPS enabled"
CASE gpsDisabled
// The provider was disabled by the user.
STC_Status = "GPS disabled"
CASE gpsOffService
// The provider is off service.
STC_Status = "GPS off service"
CASE gpsUnavailable
// The provider is temporarily unavailable.
STC_Status = "GPS unavailable"
CASE gpsAvailable
// The provider is available.
STC_Status = "GPS available"
// Requests location tracking with a maximum time between two calls to
// GPSFollowMovement(_GetLocation, 1000)
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(_GetLocation, 1000)
The code of the procedure can be as follows:
PROCEDURE _GetLocation(MyLocation)
// Update the information about the location
// Latitude and longitude
STC_Latitude = StringBuild("Latitude: %1", MyLocation.Latitude)
STC_Longitude = StringBuild("Longitude: %1", MyLocation.Longitude)
// Speed
IF MyLocation.SpeedValid = True THEN
STC_Speed = StringBuild("Speed: %1 m/s", MyLocation.Speed)
IMG_SPEED_VALIDITY = IMG_OK
ELSE
STC_Speed = "Speed: N/A"
IMG_SPEED_VALIDITY = IMG_NOTOK
END
// Altitude
IF MyLocation.AltitudeValid = True THEN
STC_Altitude = StringBuild("Altitude: %1 m", MyLocation.Altitude)
IMG_ALTITUDE_VALIDITY = IMG_OK
ELSE
STC_Altitude = "Altitude: N/A"
IMG_ALTITUDE_VALIDITY = IMG_NOTOK
END
// Direction
IF MyLocation.DirectionValid = True THEN
STC_Direction = StringBuild("Direction: %1 ° E", MyLocation.Direction)
IMG_DIRECTION_VALIDITY = IMG_OK
ELSE
STC_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?
FunctionWhen to use it? AccuracyEnergy consumption
geoTrackingXXXPermanent 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
GPSFollowMovementPermanent tracking of location changes when the application is in the foreground.Accuracy according to GPSInitParameter. Consumption according to GPSInitParameter.
GPSDetectPositionNotification of the proximity of a given location when the application is in the foreground. Accuracy according to GPSInitParameter. Consumption according to GPSInitParameter.
GPSGetPositionGet 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.
GPSLastPositionImmediately 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):
Functions
Universal Windows 10 App Universal Windows Platform App
geoAzimuthXX
geoDistanceXXX
geoGetAddressXX
geoGetAreaXXX
geoRunAppXX
geoTrackingDisableXX
geoTrackingEnableXX
geoTrackingProcedureXX
geoTrackingStatusXX
GPSDetectPositionXX
GPSEndXXX
GPSFollowMovementXXXX
GPSGetPositionXXXX
GPSInfoXX
GPSInitParameterXXX
GPSLastPositionXXXX
GPSStatusXXXX
GPSStopDetectionXX
Related Examples:
WM Geolocation Cross-platform examples (WINDEV Mobile): WM Geolocation
[ + ] This example explains how to perform proximity searches with geolocation :
- search around me
- search in a city, at a given address, or close to a specific address.
The results are displayed in a looper and in a map with markers.
Minimum version required
  • Version 16
This page is also available for…
Comments
video gpsgetposition
https://youtu.be/4MqAx_qiFts

https://windevdesenvolvimento.blogspot.com/2019/01/dicas-1987-windev-mobile-dicas-14.html


amarildo
16 Jan. 2019
Endereço das coordenadas
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/519-busca-endereco-rota-endereco-das-coordendas-523/read.awp?hl=enderecodascoordenadas

https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/2875-informatica-exemplo-google-maps-com-json-retornando-distancia/read.awp?lastview
BOLLER
10 Nov. 2018

Last update: 06/22/2023

Send a report | Local help