Android Question [Solved] webview e google maps

Discussion in 'Android Questions' started by pazzokli, Apr 24, 2019.

  1. pazzokli

    pazzokli Member Licensed User

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

    ronell Well-Known Member Licensed User

    Last edited: Apr 24, 2019
  3. pazzokli

    pazzokli Member Licensed 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
     
  4. DonManfred

    DonManfred Expert Licensed 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?
     
    ronell likes this.
  5. pazzokli

    pazzokli Member Licensed User

    Is not necessary post a project. Put a webview in a new project and write
    Code:
    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.
     
    f0raster0 likes this.
  6. f0raster0

    f0raster0 Active Member Licensed User

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

    ronell Well-Known Member Licensed User

     
  8. DonManfred

    DonManfred Expert Licensed User

    Try this

    Code:
    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, 00100%x100%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 StringAs 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 StringAs 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
     

    Attached Files:

    f0raster0 likes this.
  9. DonManfred

    DonManfred Expert Licensed User

    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.
     
    José J. Aguilar and pazzokli like this.
  10. pazzokli

    pazzokli Member Licensed 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice