Select to view content in your preferred language

Web Locate Me Button is Not Working on Android Webview

882
10
Jump to solution
10-23-2024 12:26 AM
ElieRizk
Frequent Contributor

We have a web app that shows an ESRI map with a locate me button, the button is working on the web browser, but it's 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()
                )
            }


        }
    }
}
 
0 Kudos
1 Solution

Accepted Solutions
ElieRizk
Frequent Contributor

Thank you everyone for your support.

The issue was solved after switching from jetpack compose to normal layout.

View solution in original post

0 Kudos
10 Replies
JesseCloutier
Esri Community Manager

Thanks for bringing your question to Esri Community, @ElieRizk.

Because this area is used for members to provide our team with feedback about our online community, I'd like to help get your post moved over to one of our conversation boards where it's more likely to be seen and responded to by members who can help. Which ArcGIS product are you using?

Jesse Cloutier
Community Manager, Engagement & Content
0 Kudos
ElieRizk
Frequent Contributor

@JesseCloutier Thank you.

We are using Javascript API locate widget.

0 Kudos
JesseCloutier
Esri Community Manager

@ElieRizk I've moved this conversation to the ArcGIS JavaScript Maps SDK Questions Board. All the best!

Jesse Cloutier
Community Manager, Engagement & Content
0 Kudos
ElieRizk
Frequent Contributor

@JesseCloutier Since we moved the post to this section we haven't received any feedback.
kindly any support is highly appreciated to solve the issue.

Thank You,

0 Kudos
RamaniGanason
Regular Contributor

From the error message, seems like the app do not have permission to access the devices location. Might want to check the app security or setting again if location enabled.

0 Kudos
ElieRizk
Frequent Contributor

@RamaniGanason  Location is already enabled as we mentioned in our post. 

we checked it again and the problem persists.

0 Kudos
RamaniGanason
Regular Contributor

Hi @ElieRizk , I would love to replicate this so that I'm able to help further. Can let know the tech stack that you are currently using and the android version that you are testing against.

0 Kudos
ElieRizk
Frequent Contributor

@RamaniGanason  hello, thank you for your support.

We use Kotlin Jetpack Compose as a development language, Android version 15 with the following workflow:

We have a web app javascript that shows an ESRI map with a locate ESRIJs widget, the locate widget is working fine on the web browsers, but it's not working on the Android web view yet it is working on the IOS web view, in addition on android all the needed permissions are enabled.

0 Kudos
AndyGup
Esri Regular Contributor

In case it helps with troubleshooting, the SDK's locate widget uses the native Geolocation API under the hood. So, if you can build a simple app for testing with just the Geolocation API, that functionality would be similar to the widget's.

0 Kudos