ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Geolocation functions
  • Special cases
  • Operating mode in iPhone/iPad
  • Required permissions
  • Required application feature
  • Browsers allowing the geolocation
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
Retrieves the activation status of the geolocation provider or asks to be notified when the status changes.
WEBDEV - Browser code Retrieves the activation status of the geolocation provider.
Example
// Checks the status of the GPS provider
IF GPSStatus() = gpsDisabled THEN
Info("Geolocation is not enabled.")
END
Universal Windows 10 AppAndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst
// Branches a notification procedure if the status of the GPS is modified
GPSStatus(ProcGPSStatus)
// Procedure called whenever the status of the GPS is modified
PROCEDURE ProcGPSStatus(GPS_Status is int)
 
IF GPS_Status = gpsUnavailable THEN
Info("Geolocation not available.")
END
Syntax

Retrieving the activation status of the provider Hide the details

<Result> = GPSStatus()
<Result>: Integer constant
Activation status of the location provider. The following values can be returned:
gpsDisabledThe provider is disabled.
gpsEnabledThe provider is enabled.
gpsErrorError while retrieving the activation status of the provider. To get more details on the error, use ErrorInfo.
WINDEVWEBDEV - Browser codeUniversal Windows 10 App This constant is not available.
WINDEVUniversal Windows 10 AppAndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst

Asking to be notified when the activation status changes Hide the details

GPSStatus(<WLanguage procedure>)
<WLanguage procedure>: Procedure name
WLanguage procedure ("callback" procedure) called for each notification.
This procedure has the following format:
PROCEDURE <Procedure name>(<Status>)
<Status> is an integer constant corresponding to the new status of the provider.
It can take the following values:
gpsAvailableThe provider is available.
gpsDisabledThe provider was disabled by the user.
gpsEnabledThe provider was enabled by the user.
gpsOffServiceThe provider is off service.
gpsUnavailableThe provider is temporarily unavailable.
Remarks

Special cases

  • AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst It is recommended to reset the parameters of the location provider with GPSInitParameter before retrieving the status of this provider.
  • Universal Windows 10 AppAndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst To stop receiving the notifications when the status changes, call GPSStatus while passing an empty string ("") as parameter or use GPSEnd.
iPhone/iPadIOS WidgetMac Catalyst

Operating mode in iPhone/iPad

When a GPS function is first run, the system requests geolocation permission from the user. If the user refuses, all the GPS functions used in the rest of the application will fail (fatal error).
To re-allow the use of GPS for this application, the system configuration of the application must be modified.
AndroidAndroid Widget

Required permissions

The call to this function modifies the permissions required by the application.
Required permission: 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.
Universal Windows 10 App

Required application feature

When this function is used, an application feature is declared in the application generation wizard.
Required feature: Geolocation
This feature allows the applications to access the geolocation features found on the device or on the computer.
WEBDEV - Browser code

Browsers allowing the geolocation

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.
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.
Android GPS Android (WINDEV Mobile): Android GPS
[ + ] This example presents the use of the GPS functions of WLanguage in an Android application.
It is used to retrieve at regular interval:
- The latitude
- The longitude
- The altitude
- The speed
- The direction
Component: wd300java.dll
Minimum version required
  • Version 15
This page is also available for…
Comments
Exemplo
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3701-trabalhando-com-gps/read.awp
Boller
13 Mar. 2021
EXAMPLE: GPS status and on / off GPS via Java
FONTE:

http://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/9-windev-mobile-verifica-gps-ligado-posicao/read.awp

---x---

Example 01:
#####################################################

Procedure GPS_VerificaStatus()

Retorno is string = ""

GloLatitude , GloLongitude is real = 0

GPSInitParameter(gpsSatellite,gpsPrecisionHigh)

// Recuperação da posição
Retorno is geoPosition = GPSGetPosition() // 2000 = Intervalo máxo,p de 20 segundos

GloLatitude = NumToString(Retorno..Latitude,"+-10.6f")
GloLongitude = NumToString(Retorno..Longitude,"+-10.6f")

Retorno = GloLatitude +"; "+ GloLongitude

IF GloLatitude = 0 AND GloLongitude = 0 OR GloLatitude = null AND GloLongitude = null
ToastDisplay("GPS Desligado!!!")
END

RESULT(Retorno )

---x---



Example 02:
#####################################################

//Java GPS_On

import android.app.Activity;
import java.lang.*;
import android.util.*;
import java.lang.Exception;
import android.util.Log;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

PUBLIC static void GPS_On()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", True);
getActiviteEnCours().sendBroadcast(intent);
}

---x---

//Java GPS_Off

import android.app.Activity;
import java.lang.*;
import android.util.*;
import java.lang.Exception;
import android.util.Log;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

PUBLIC static void GPS_Off()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", False);
getActiviteEnCours().sendBroadcast(intent);
}


---x---

OBS.:
You must enable these options in the Android Manifest XML Windev Mobile

A) Android.Permission.WRITE_SECURE_SETTINGS

B) Android.Permission.WRITE_SETTINGS

---x---



Example 03
#####################################################
Another way to test whether this off GPS:

// GLOBAL
GloGpsAtivado is boolean = False

//Open Window
Procedure GPS_Inicializar()

GPSInitParameter(gpsSatellite,gpsPrecisionHigh +gpsSpeed)

IF GPSStatus() <> gpsEnabled THEN

Popup("Para melhorar a precisão da sua localização, ative o seu GPS","L")

gloStatusGps = False

ELSE
ChangeGPSStatus(GPSStatus())
END

GPSStatus(ChangeGPSStatus)

---x---

//Procedure Global

Procedure ChangeGPSStatus(nStatus)
IF gnCurrentStatus = nStatus THEN
RETURN
END

gnCurrentStatus = nStatus

IF nStatus = gpsEnabled OR nStatus = gpsAvailable THEN

GPSFollowMovement(GetPosition,300)

END

SWITCH nStatus
CASE gpsEnabled
GloGpsAtivado = True // <------------- Ligado
CASE gpsDisabled
GloGpsAtivado = False // <------------- Desligado
gloStatusGps = False
CASE gpsOffService
CASE gpsUnavailable
CASE gpsAvailable
END

adrianoboller
14 Feb. 2015

Last update: 06/23/2023

Send a report | Local help