Android Question [Solved] webview e google maps

pazzokli

Active Member
Licensed User
Longtime User
Hi, why if I put a webview in my project and I do
B4X:
WebView1.LoadUrl("https://www.google.com/maps")
is not possible find my position? with smatphone's browser I've no problem
 

pazzokli

Active Member
Licensed User
Longtime User
I don't need coordinate. My question is why on the browser I can see current location and with the webview no?
A couple of week ago I did it, now is not possible. If I click on the icon to move blue dot on the actual position I get error
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You are not providing any useful informations! Upload a small project which shows the issue.
How do you expecting we could help with this less informations? You said you got an error: WHICH one?
 
Upvote 0

pazzokli

Active Member
Licensed User
Longtime User
Is not necessary post a project. Put a webview in a new project and write
B4X:
WebView1.LoadUrl("https://www.google.com/maps")
Webview show the map. If click on the circle that move the map in your location it doesn't work.
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Is not necessary post a project. Put a webview in a new project and write
B4X:
WebView1.LoadUrl("https://www.google.com/maps")
Webview show the map. If click on the circle that move the map in your location it doesn't work.

same question here with a couple of our Apps, years ago it worked.. but I have now the same situation like @pazzokli .
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Try this

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim WebView1 As WebView

    Dim WebViewExtras1 As WebViewExtras
    Dim WebViewSetting1 As WebViewSettings
    Dim spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    WebView1.Initialize("WWW")
    WebView1.JavaScriptEnabled=True
    WebViewExtras1.addJavascriptInterface(WebView1, "B4A") ' NOT ESSENTIAL
    WebViewExtras1.addWebChromeClient(WebView1,"Chrome")
    WebViewSetting1.setDatabaseEnabled(WebView1, True)
    '   WebViewSetting1.setDOMStorageEnabled(WebView1, True)
 
    Log("DefaultWebViewDatabasePath: "&WebViewSetting1.getDatabasePath(WebView1))
    '   the WebView will fail to create any databases if the database path is NOT set
    WebViewSetting1.setDatabasePath(WebView1, "")
    Log("NewWebViewDatabasePath: "&WebViewSetting1.getDatabasePath(WebView1))
 
 
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
    'Dim DefaultWebChromeClient1 As DefaultWebChromeClient
    'DefaultWebChromeClient1.Initialize("DefaultWebChromeClient1")
    'WebViewExtras1.SetWebChromeClient(DefaultWebChromeClient1)
  
    WebView1.LoadUrl("https://www.google.com/maps")
    ' Need Runtimepermissions and the permission must be granted
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No Location permission!", True)
    End If

End Sub
Sub WWW_OverrideUrl (Url As String) As Boolean
  
End Sub

Sub WWW_PageFinished (Url As String)
    Log($"WWW_PageFinished(${Url})"$)

    'Log(Javascript)
    'CallSubDelayed(Me,"set_focus")
End Sub
Sub GetVarFromWebview(WebVar As String)
    Log($"GetVarFromWebview(${WebVar})"$)
End Sub
Sub WWW_UserAndPasswordRequired (Host As String, Realm As String) As String()
  
End Sub
Sub Chrome_GeolocationPermissionsRequest As Int
    Log($"Chrome_GeolocationPermissionsRequest()"$)
    ' Return 1 (allowed)
    Return 1
End Sub
Sub Chrome_ProgressChanged(NewProgress As Int)
  
End Sub
Sub Chrome_ProgressChanged2(wv As WebView, NewProgress As Int)
  
End Sub

PD: Tested on B4A 9 running on Android 9 device using targetsdk = 26
 

Attachments

  • googlelocation.zip
    8.1 KB · Views: 285
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Put a webview in a new project and write
I expect you are using targetsdk 26 so you have to adapt your app to follow the rules. In this case; Requesting permission using runtimepermissions library.
See my last answer for a working solution (at least for me). I am using a webchromeclient here as the webview itself uses an old android api.
 
Upvote 0

pazzokli

Active Member
Licensed User
Longtime User
Don, your example work!!!
Yes I use sdk26 and all the permission rules but with the simple webview I had that problem.
Your solution is great. Now I analyze your code in order to understand how use webviewextra and ChromeClient
 
Upvote 0
Top