Android Question webviewextra2.2 geolocation

kkkpe

Active Member
Licensed User
Longtime User
Hi, I have a strange behavior using the webviewextra2.2 library with a web page that has a simple geolocation function.
In practice the coordinates are read only once instead of being updated regularly. Obviously if I access the page directly with a browser everything works. I pass you the code that I used to do the tests:
geolocalizzazione:
$(document).ready(function(){
                let watchId;
                startTracking();
                function startTracking()
                {
                    if ("geolocation" in navigator) {
                        watchId = navigator.geolocation.watchPosition(
                        (position) => {
                            //alert('ss');
                            latitudine = position.coords.latitude;
                            longitudine = position.coords.longitude;
                            $('#lat').text(latitudine);
                            $('#long').text(longitudine);
                        },
                        (error) => {
                            console.log("Errore durante il tracking:", error.message);
                        },
                        {
                            enableHighAccuracy: true, // Usa il GPS per maggiore precisione
                            maximumAge: 0, // Non usa dati memorizzati
                            timeout: 10000 // Timeout massimo per ottenere la posizione
                        }
                        );
                    } else {
                        console.error("Il browser non supporta la geolocalizzazione.");
                    }
                }
            });


b4x:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private WebView1 As WebView
    
    Private WebViewExtras1 As WebViewExtras
    Private DWVC As DefaultWebViewClient
    Private DWCC As DefaultWebChromeClient
    Private JSClient As DefaultJavascriptInterface
    Private rp As RuntimePermissions
    
End Sub




'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    

    
    
    Root.LoadLayout("Lay_webview2")
    
    WebViewExtras1.Initialize(WebView1)
    JSClient.Initialize
    DWVC.Initialize("WebViewClient")
    DWCC.Initialize("WebChromeClient")
    WebViewExtras1.getsettings.SetAllowContentAccess(True)
    WebViewExtras1.GetSettings.SetAllowFileAccess(True)
    WebViewExtras1.GetSettings.setDOMStorageEnabled(True)
    WebViewExtras1.GetSettings.setDatabaseEnabled(True)
    WebViewExtras1.SetWebViewClient(DWVC)
    WebViewExtras1.SetWebChromeClient(DWCC)
    WebViewExtras1.AddJavascriptInterface(JSClient,"B4A")
    WebViewExtras1.JavaScriptEnabled=True
    WebViewExtras1.GetSettings.SetJavaScriptCanOpenWindowsAutomatically(True)
    WebViewExtras1.GetSettings.SetAppCacheEnabled(True)
    WebViewExtras1.GetSettings.SetBuiltInZoomControls(True)
    WebViewExtras1.GetSettings.setSupportZoom(True)
    WebViewExtras1.GetSettings.SetGeolocationEnabled(True)
    WebViewExtras1.GetSettings.SetMediaPlaybackRequiresUserGesture(False)
    

    WebView1.LoadUrl("https://pellegrino.vendingmanager.it/mobile/test2.php")
    
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Wait For B4xPage_PermissionResult(Permission As String,Result As Boolean)
    If(Result)Then
        
    Else
        ToastMessageShow("Non hai permessi per accedere al Telefono", True)
        
    End If
 
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For B4xPage_PermissionResult(Permission As String,Result As Boolean)
    If(Result)Then
        
    Else
        ToastMessageShow("Non hai permessi di geolocalizzazione", True)
        
    End If
    


    
End Sub

Sub B4XPage_Appear
    
End Sub



Sub WebViewClient_OverrideUrl (url As String) As Boolean
    Log("OVERRIDE URL:")
    Log(url)
End Sub


Sub WebViewClient_PageFinished (Url As String)
    Log($"webviewclient_PageFinished(${Url})"$)
    
End Sub

Sub WebViewClient_UserAndPasswordRequired (Host As String, Realm As String) As String()
    
End Sub



Sub WebChromeClient_GeolocationPermissionsRequest As Int
    Log($"Chrome_GeolocationPermissionsRequest()"$)
    ' Return 1 (allowed)
    Return 1
End Sub


Sub WebChromeClient_ConsoleMessage(ConsoleMessage1 As ConsoleMessage) As Boolean
    Log(ConsoleMessage1.Message)
    Return True
End Sub



Sub WebViewClient_ReceivedSslError(SslErrorHandler1 As SslErrorHandler, SslError1 As SslError)
    Select SslError1.GetPrimaryError
        Case SslError1.SSL_DATE_INVALID
            Log("SSL error: SSL_DATE_INVALID")
        Case SslError1.SSL_EXPIRED
            Log("SSL error: SSL_EXPIRED")
        Case SslError1.SSL_IDMISMATCH
            Log("SSL error: SSL_IDMISMATCH")
        Case SslError1.SSL_INVALID
            Log("SSL error: SSL_INVALID")
        Case SslError1.SSL_MAX_ERROR
            Log("SSL error: SSL_MAX_ERROR")
        Case SslError1.SSL_NOTYETVALID
            Log("SSL error: SSL_NOTYETVALID")
        Case SslError1.SSL_UNTRUSTED
            Log("SSL error: SSL_UNTRUSTED")
    End Select
    SslErrorHandler1.Proceed
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
To me this example works. Trial
 

Attachments

  • kkkpe.zip
    11.2 KB · Views: 96
Upvote 0

kkkpe

Active Member
Licensed User
Longtime User
this is the solution:
manifest:
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)

gps1:
    If GPS1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GPS device.", True)
        StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
    Else
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
        'GPS1.Start(0,0)
        WebView1.LoadUrl("https://pellegrino.vendingmanager.it/mobile/test2.php")
    End If
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
This doesn't explain why it worked with WebWiewExtra 1.42 but not 2.20
 
Upvote 0
Top