October 22, 2024
Chicago 12, Melborne City, USA
Android

web locate me button is not working on android webview


we have a web app that showing an ezri map with locate me button, the button is working on the web browser, but its not working on the android web view, also the location permission is enabled, see code below:

the error we get on the CONSOLE:
INFO:CONSOLE(285)] "Error: User denied Geolocation

the location permission enabled:

requestPermissions(
    activity,
    arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION),
    1)

@SuppressLint("SetJavaScriptEnabled")
@Composable
fun LoadWebView(url: String) {
    MyTheme {
        Surface(
            modifier = Modifier.fillMaxSize(),
            color = MaterialTheme.colorScheme.background
        ) {
            Column {
               
                val state = rememberWebViewState(
                    url
                )
                val loadingState = state.loadingState
                if (loadingState is LoadingState.Loading) {
                    LinearProgressIndicator(
                        progress = loadingState.progress,
                        modifier = Modifier.fillMaxWidth()
                    )
                }
                WebView(
                    state, onCreated = {
                        it.settings.javaScriptEnabled = true
                        it.settings.allowContentAccess = true
                        it.settings.allowFileAccess = true
                        it.settings.loadWithOverviewMode = true
                        it.settings.useWideViewPort = true
                        it.settings.domStorageEnabled = true
                        it.settings.javaScriptCanOpenWindowsAutomatically=true
                        it.settings.databaseEnabled = true
                        it.settings.setSupportMultipleWindows(true)
                        it.settings.setGeolocationEnabled(true)
                        it.webChromeClient = object : WebChromeClient() {
                            override fun onGeolocationPermissionsShowPrompt(
                                origin: String,
                                callback: GeolocationPermissions.Callback
                            ) {
                                callback.invoke(origin, true, false)
                            }
                        }
                    }, modifier = Modifier.fillMaxSize()
                )
            }


        }
    }
}



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video