Android Question HTML5 geolocation in webview

Celso

Member
Licensed User
Hi, Im trying to get location in webview using javascript but not success, can someone give me a way to do that?
The site i'm trying is www.cl4.com.br, after choose a item, click in a icon and not get the same result as opening in browser.
 

Celso

Member
Licensed User
Thanks Erel, the problem is, I'm not owner the site.
So, the client ask abou a client to install in their users.
I'm trying your second option, without success too.
 

Celso

Member
Licensed User
this is my try
B4X:
#Region  Project Attributes
   #ApplicationLabel: Permission Request
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals

End Sub


Sub Globals
    Dim WebView1 As WebView
    Dim client As DefaultWebChromeClient
   Dim murl As String = "https://www.cl4.com.br/map.php?id=17"  
End Sub

Sub Activity_Create(FirstTime As Boolean)
 
    Activity.LoadLayout("main")  
    Dim webextra As WebViewExtras   
    webextra.Initialize(WebView1)
    client.Initialize("geo")
   webextra.GetSettings.SetGeolocationEnabled(True)
   webextra.GetSettings.GetJavaScriptCanOpenWindowsAutomatically
    webextra.ZoomEnabled = True
    webextra.SetWebChromeClient(client)
   
    webextra.JavaScriptEnabled = True
    WebView1.LoadUrl(murl)
End Sub
 
Last edited:

Celso

Member
Licensed User
success
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Layout")   
   MyWebViewExtras.addWebChromeClient(WebView1, "AbreGeo")
   WebView1.JavaScriptEnabled = True
   WebView1.LoadUrl("https://www.cl4.com.br")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub AbreGeo_GeolocationPermissionsRequest As Int
   Dim Response As Int
   Response=Msgbox2("Autorizar usar localização?", "Autorização Necessária:", "Aceitar", "", "Recusar", Null)
   If Response=DialogResponse.POSITIVE Then
       ToastMessageShow("Permitido", True)
       Return MyWebViewExtras.GEOLOCATION_PERMISSION_ALLOW_AND_REMEMBER
   Else
       ToastMessageShow("Rejeitado", True)
       Return MyWebViewExtras.GEOLOCATION_PERMISSION_DISALLOW
   End If
End Sub
Thanks Erel
 
Top