PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Overview
  • Implementing the GPS management
  • Checking whether the GPS is enabled
  • Be notified when the GPS status changes
  • Following the move
  • 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
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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.
AndroidiPhone/iPadUniversal Windows 10 App In the phone applications, you have the ability to:
  • 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.
  • ...
Versions 17 and later
iPhone/iPad Some geolocation functions can now be used in iPhone/iPad applications.
New in version 17
iPhone/iPad Some geolocation functions can now be used in iPhone/iPad applications.
iPhone/iPad Some geolocation functions can now be used in iPhone/iPad applications.
Versions 17 and later
iPhone/iPad Some geolocation functions can now be used in Universal Windows 10 App mode.
New in version 17
iPhone/iPad Some geolocation functions can now be used in Universal Windows 10 App mode.
iPhone/iPad Some geolocation functions can now be used in Universal Windows 10 App mode.
AndroidiPhone/iPad Remarks:
  • Versions 17 and later
    Android The Map control is used to view a location. See Map control for more details.
    New in version 17
    Android The Map control is used to view a location. See Map control for more details.
    Android The Map control is used to view a location. See Map control for more details.
  • Versions 21 and later
    AndroidiPhone/iPad You also have the ability to follow the moves of user, even when the application is closed. See Implementing geolocation tracking for more details.
    New in version 21
    AndroidiPhone/iPad You also have the ability to follow the moves of user, even when the application is closed. See Implementing geolocation tracking for more details.
    AndroidiPhone/iPad You also have the ability to follow the moves of user, even when the application is closed. See Implementing geolocation tracking for more details.
Versions 16 and later
WEBDEV - Browser code Some geolocation functions can now be used in browser code.
WEBDEV - Browser code In the Web sites, you have the ability to interact with the GPS features of the device, if available (mobile device in most cases). You can retrieve or track a location in a website displayed on a mobile device.
Caution: Geolocation is only available on certain modern browsers:
  • FireFox from version 3.5,
  • Chrome from version 5.0.342.1,
  • Opera from version 10.6,
  • Safari from version 5.0.
During the call to a geolocation function, the browser requests a location authorization.
New in version 16
WEBDEV - Browser code Some geolocation functions can now be used in browser code.
WEBDEV - Browser code In the Web sites, you have the ability to interact with the GPS features of the device, if available (mobile device in most cases). You can retrieve or track a location in a website displayed on a mobile device.
Caution: Geolocation is only available on certain modern browsers:
  • FireFox from version 3.5,
  • Chrome from version 5.0.342.1,
  • Opera from version 10.6,
  • Safari from version 5.0.
During the call to a geolocation function, the browser requests a location authorization.
WEBDEV - Browser code Some geolocation functions can now be used in browser code.
WEBDEV - Browser code In the Web sites, you have the ability to interact with the GPS features of the device, if available (mobile device in most cases). You can retrieve or track a location in a website displayed on a mobile device.
Caution: Geolocation is only available on certain modern browsers:
  • FireFox from version 3.5,
  • Chrome from version 5.0.342.1,
  • Opera from version 10.6,
  • Safari from version 5.0.
During the call to a geolocation function, the browser requests a location authorization.
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, all you have to do is call GPSStatus and specify the name of procedure used to manage 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"
// Asks to follow the move with a maximum time between two calls to
// GPSFollowMovement(_GetPosition, 1000)
OTHER CASE
END
In this procedure, if the GPS is enabled, a specific procedure is used to follow the movement.
WEBDEV - Browser code This feature is not available.

Following the move

To follow the move of device, all you have to do is call GPSFollowMovement and specify the name of procedure that will be used to manage the move.
Example:
GPSFollowMovement(_GetPosition, 1000)
The code of the procedure can be as follows:
PROCEDURE _GetPosition(MyPosition)
 
// Update the information about the location
// Latitude and longitude
STC_Latitude = StringBuild("Latitude: %1", MyPosition..Latitude)
STC_Longitude = StringBuild("Longitude: %1", MyPosition..Longitude)
 
// Speed
IF MyPosition..SpeedValid = True THEN
STC_Speed = StringBuild("Speed: %1 m/s", MyPosition..Speed)
IMG_SPEED_VALIDITY = IMG_OK
ELSE
STC_Speed = "Speed: N/A"
IMG_SPEED_VALIDITY = IMG_NOTOK
END
 
// Altitude
IF MyPosition..AltitudeValid = True THEN
STC_Altitude = StringBuild("Altitude: %1 m", MyPosition..Altitude)
IMG_ALTITUDE_VALIDITY = IMG_OK
ELSE
STC_Altitude = "Altitude: N/A"
IMG_ALTITUDE_VALIDITY = IMG_NOTOK
END
 
// Direction
IF MyPosition.DirectionValid = True THEN
STC_Direction = StringBuild("Direction: %1 ° E", MyPosition..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(MyPosition..MeasurementDate..Date), ...
TimeToString(MyPosition..MeasurementDate..Time))
STC_Last_update..Visible = True
In this code, MyPosition is a geoPosition variable. The properties of this type of variable are used to find out the location characteristics.
WEBDEV - Browser code The WLanguage procedure used requires specific parameters.

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.
WEBDEV - Browser code This feature is not available.
AndroidiPhone/iPad
Versions 21 and later
Implementing geolocation tracking

Overview

On a mobile device, it is sometimes necessary to follow the moves of the user even when the mobile application is closed or in background.
This tracking must be performed by consuming as less as possible the resources of the mobile device (especially the battery). This is possible by reducing the precision of tracking in relation to a standard GPS tracking.

Principle and implementation

To manage location tracking:
  1. Enable location tracking with geoTrackingEnable.
  2. Define the procedure called when changing the location with geoTrackingProcedure. This function must be used in the initialization process of project.
You can:
Caution: This location tracking has low precision. The events are sent only if significant changes of location occur and at time intervals exceeding several minutes. For information, the sending conditions per platform are as follows:
  • iPhone/iPad The events regarding the change of location are not sent if the location did not change by more than 500 meters, or if the time interval is less than 5 minutes (December 2014).
  • Android Location change events are sent at intervals that range from 30 seconds to 10 minutes, depending on the distance between locations.
For a more precise tracking, you must use GPSFollowMovement. However, this function:
  • requires the application to be started,
  • Android requires the application to be in the foreground,
  • consumes more battery.

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.
iPhone/iPad The iOS system limits the operations that can be performed when the application is started in background. Therefore:
  • The execution of background operation cannot exceed ten seconds.
  • No window can be opened and no interface can be displayed (however, a notification can be sent).
Reminder: To find out 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 background by the tracking management.
New in version 21
Implementing geolocation tracking

Overview

On a mobile device, it is sometimes necessary to follow the moves of the user even when the mobile application is closed or in background.
This tracking must be performed by consuming as less as possible the resources of the mobile device (especially the battery). This is possible by reducing the precision of tracking in relation to a standard GPS tracking.

Principle and implementation

To manage location tracking:
  1. Enable location tracking with geoTrackingEnable.
  2. Define the procedure called when changing the location with geoTrackingProcedure. This function must be used in the initialization process of project.
You can:
Caution: This location tracking has low precision. The events are sent only if significant changes of location occur and at time intervals exceeding several minutes. For information, the sending conditions per platform are as follows:
  • iPhone/iPad The events regarding the change of location are not sent if the location did not change by more than 500 meters, or if the time interval is less than 5 minutes (December 2014).
  • Android Location change events are sent at intervals that range from 30 seconds to 10 minutes, depending on the distance between locations.
For a more precise tracking, you must use GPSFollowMovement. However, this function:
  • requires the application to be started,
  • Android requires the application to be in the foreground,
  • consumes more battery.

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.
iPhone/iPad The iOS system limits the operations that can be performed when the application is started in background. Therefore:
  • The execution of background operation cannot exceed ten seconds.
  • No window can be opened and no interface can be displayed (however, a notification can be sent).
Reminder: To find out 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 background by the tracking management.
Implementing geolocation tracking

Overview

On a mobile device, it is sometimes necessary to follow the moves of the user even when the mobile application is closed or in background.
This tracking must be performed by consuming as less as possible the resources of the mobile device (especially the battery). This is possible by reducing the precision of tracking in relation to a standard GPS tracking.

Principle and implementation

To manage location tracking:
  1. Enable location tracking with geoTrackingEnable.
  2. Define the procedure called when changing the location with geoTrackingProcedure. This function must be used in the initialization process of project.
You can:
Caution: This location tracking has low precision. The events are sent only if significant changes of location occur and at time intervals exceeding several minutes. For information, the sending conditions per platform are as follows:
  • iPhone/iPad The events regarding the change of location are not sent if the location did not change by more than 500 meters, or if the time interval is less than 5 minutes (December 2014).
  • Android Location change events are sent at intervals that range from 30 seconds to 10 minutes, depending on the distance between locations.
For a more precise tracking, you must use GPSFollowMovement. However, this function:
  • requires the application to be started,
  • Android requires the application to be in the foreground,
  • consumes more battery.

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.
iPhone/iPad The iOS system limits the operations that can be performed when the application is started in background. Therefore:
  • The execution of background operation cannot exceed ten seconds.
  • No window can be opened and no interface can be displayed (however, a notification can be sent).
Reminder: To find out 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 background by the tracking management.
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
Android Android
Versions 17 and later
iPhone/iPad iPhone/iPad
New in version 17
iPhone/iPad iPhone/iPad
iPhone/iPad iPhone/iPad
Universal Windows 10 App Universal Windows App
WEBDEV - Browser code Browser code
geoAzimuthXX
geoDistanceXXX
Versions 17 and later
geoRunApp
New in version 17
geoRunApp
geoRunApp
XX
Versions 17 and later
geoGetAddress
New in version 17
geoGetAddress
geoGetAddress
XX
Versions 21 and later
geoTrackingEnable
New in version 21
geoTrackingEnable
geoTrackingEnable
XX
Versions 21 and later
geoTrackingDisable
New in version 21
geoTrackingDisable
geoTrackingDisable
XX
Versions 21 and later
geoTrackingStatus
New in version 21
geoTrackingStatus
geoTrackingStatus
XX
Versions 21 and later
geoTrackingProcedure
New in version 21
geoTrackingProcedure
geoTrackingProcedure
XX
GPSStopDetectionXX
GPSLastPositionXXXX
GPSDetectPositionXX
GPSStatusXXXX
GPSInfoXX
GPSInitParameterXXX
GPSGetPositionXXXX
GPSFollowMovementXXXX
GPSEndXXX
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