AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de geolocalización
  • Managing locks
  • Retrieved properties
  • Modo de funcionamiento en iPhone/iPad
  • Required permissions
  • Browsers allowing the geolocation
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Retrieves information about the current device position.
Ejemplo
MyLocation is geoPosition
MyLocation = GPSGetPosition()
// Checks the position validity with ErrorOccurred
IF ErrorOccurred THEN RETURN
Info("Latitude: " + MaPosition.Latitude)  
Info("Longitude: " + MaPosition.Longitude)
WEBDEV - Código Navegador
// Geolocation from WEBDEV, a browser procedure is called.
// Process performed from a button whose action is "none"
GPSGetPosition(BrowserProc, 200)
// "BrowserProc" browser procedure
PROCEDURE BrowserProc(MyLocation is geoPosition, nMyError is int)
SWITCH nMyError
	CASE gpsErrorOK
		// No error was detected
		PAGE_Page1.SAI_SansNom1 = MyPosition.Altitude + " " + MyPosition.Longitude
	CASE gpsErrorRights
		PAGE_Page1.SAI_SansNom1 = "The browser does not have the rights " + ...
				"to use the geolocation (or non-HTTPS site)."
	CASE gpsErrorPosition
		PAGE_Page1.EDT_NoName1 = "Unable to define the position " + ...
				"(internal error of provider for example)."
	CASE gpsErrorTimeout
		PAGE_Page1.EDT_NoName1 =  ...
			"The location could not be retrieved within the timeout."
	OTHER CASE
		PAGE_Page1.EDT_NoName1 = "Undefined error"
END
Sintaxis
WINDEVAndroidWidget Android iPhone/iPadIOS WidgetMac Catalyst

Retrieving information about a device (mobile, ...) Ocultar los detalles

<Result> = GPSGetPosition([<Timeout> [, <Message>]])
<Result>: geoPosition variable
geoPosition variable containing information about the device position. If the position is invalid, the ErrorOccurred variable is set to True and the error details are returned by ErrorInfo.
Android The PositionValid property of the geoPosition type determines if the position is valid.
<Timeout>: Optional integer or optional Duration
Maximum timeout (in hundredths of a second) for updating the device position.
  • An error occurs if the timeout ends before the position of the device is updated. This error can be detected by the ErrorOccurred variable and the error details can be returned by ErrorInfo.
  • If this parameter is not specified, the timeout is set to 1 minute.
Note: This parameter can correspond to:
  • an integer corresponding to the number of hundredths of a second,
  • a Duration variable,
  • the duration in a readable format (e.g., 1 s or 10 ms).
<Message>: Optional character string
Message of hourglass displayed when updating the position.
Note This parameter is only taken into account if the call is made in the application's main thread.
WINDEV This parameter is ignored.
WEBDEV - Código Navegador

Retrieving the information in browser code Ocultar los detalles

GPSGetPosition([<WLanguage procedure> [, <Timeout>]])
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure in browser code ("callback") called when the location is retrieved.
This procedure has the following format:
PROCEDURE <Procedure name>(<Position>,<Error>)
where:
  • <Error> is an Integer constant corresponding to the error code and that can take the following values:
    gpsErrorOKNo error was detected.
    gpsErrorPositionUnable to determine the location (e.g., access provider internal error).
    gpsErrorRights
    • The browser has no sufficient rights to use geolocation.
    • The browser is recent and the site is not using the HTTPS secure protocol.
    gpsErrorTimeoutThe location could not be retrieved within the timeout.
<Timeout>: Optional integer or optional Duration
Maximum timeout (in hundredths of a second) for updating the device position.
  • If this timeout ends before the device position is updated, gpsErrorTimeOut is returned in the <Error> parameter of the WLanguage procedure.
  • If this parameter is not specified, the timeout is set to 1 minute.
Note: This parameter can correspond to:
  • an integer corresponding to the number of hundredths of a second,
  • a Duration variable,
  • the duration in a readable format (e.g., 1 s or 10 ms).
Observaciones

Managing locks

GPSGetPosition blocks execution until the current device location is retrieved or until the timeout defined by the <Timeout> parameter expires.
If the function is called in the main thread of the application, an hourglass will be displayed during the function execution. The message displayed by the hourglass can be specified via the <Message> parameter.
Otherwise, the execution of secondary thread will be locked during the function execution and no hourglass will be displayed.
WEBDEV - Código Navegador This function is not locking.
Note: To find out the last known position of the device without delay, use the GPSLastPosition function.. Caution, the positioning information that was retrieved may not correspond to the current device position if the device was moved while the GPS signal was not valid for example. You can use the MeasurementDate property of the geoPosition variable to determine the date and time at which the position was calculated.
AndroidWidget Android iPhone/iPadIOS WidgetMac Catalyst

Retrieved properties

  • To determine if a value was assigned to the Speed, Accuracy, Direction or Altitude properties of a geoPosition variable when the location was retrieved, use the SpeedValid, AccuracyValid, DirectionValid and AltitudeValid properties.
  • To reinitialize a geoPosition variable, use VariableReset.
  • AndroidWidget Android iPhone/iPadIOS WidgetMac Catalyst It is recommended to reset the parameters of the location provider with GPSInitParameter before retrieving a location.
  • The positioning information retrieved corresponds to the device's last known position: it may therefore not correspond to the device's current position if, for example, the device has been moved while the GPS signal was invalid. You can use the MeasurementDate property of the geoPosition variable to determine the date and time at which the position was calculated.
  • Speed, Accuracy, Direction and Altitude will be specified only if the location provider allows it (otherwise, these properties will take their default value).
    AndroidWidget Android The location provider can be configured with GPSInitParameter.
iPhone/iPadIOS WidgetMac Catalyst

Modo de funcionamiento en iPhone/iPad

Cuando se ejecuta por primera vez una función GPS, el sistema solicita permiso de geolocalización al usuario. Si el usuario se niega, todas las funciones GPS utilizadas en el resto de la aplicación fallarán (error fatal).
Para volver a permitir el uso del GPS en esta aplicación, es necesario modificar la configuración del sistema de la aplicación.
AndroidWidget Android

Required permissions

This function changes the permissions required by the application.
Permission required: ACCESS_FINE_LOCATION.
Android 11 specific case: This function requires the ACCESS_BACKGROUND_LOCATION permission to access the device's location.
This permission allows using the function when the application is in the background.
If the application needs to use background location:
  • Manually add the "ACCESS_BACKGROUND_LOCATION" permission in the Android application generation wizard.
  • Explicitly request background location permission with PermissionRequest. For example:
    PermissionRequest(permBackgroundLocation, Callback)
    INTERNAL PROCEDURE Callback(p is Permission)
    	IF p.Granted THEN
    		// Functions that require background location access can be used
    	END
    END
A window allows users to:
  • allow access to the device location while the application is in the background,
  • allow access to the location only while the application is in use,
  • deny access to the location. The user can also change these permissions at any time in the Android settings.

Remarks:
  • Follow Google's guidelines for applications that require background location access. For more details, see https://support.google.com/googleplay/android-developer/answer/9799150. If these conditions are not met (especially user information requirements), applications may not be accepted for publication on Google Play.
  • The background location permission should only be requested if the location permission has been granted. Otherwise, PermissionRequest will fail.
  • If the option chosen by the user for the background location access request is more restrictive than the option chosen for the location access request, the application will be automatically restarted.
  • On devices running Android 10 or earlier, if location permission has been granted to the application, the background location permission will be granted without displaying a window.
WEBDEV - Código Navegador

Browsers allowing the geolocation

During the call to a geolocation function, the browser requests a location authorization.Note: As of Chrome 50 (including Android), the function GPSGetPosition function can only be used on secure sites (via an SSL certificate, for example). If the site is not secured, the function returns a result that cannot be used. During the test in local (localhost), the function operates properly.
Clasificación Lógica de negocio / UI: Lógica de negocio
Componente: wd300java.dll
Versión mínima requerida
  • Versión 15
Esta página también está disponible para…
Comentarios
Exemplo
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3701-trabalhando-com-gps/read.awp
Boller
13 03 2021
Video GpsGetPosition
https://youtu.be/4MqAx_qiFts

https://windevdesenvolvimento.blogspot.com/2019/01/dicas-1987-windev-mobile-dicas-14.html
amarildo
16 01 2019
GPS Functions
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 11 2018
Video Trajeto Mapa
https://youtu.be/bSk0ysOlacE
amarildo
03 11 2018

Última modificación: 27/03/2025

Señalar un error o enviar una sugerencia | Ayuda local