I use Gelocation in my Android browser, and it says user denied geolocation.

Asked 2 years ago, Updated 2 years ago, 109 views

I'm making an Android application using Geolocation.

Geolocation seems to support HTml better than Android, so Android simply loaded the HTml file on the sdcard, and the imported HTml file was implemented to use Geolocation to track the location.

But when I go into Chrome, I can't track the location, and user denied appears, so I want to run it with another browser, but if I keep running it, it seems to run in Chrome.

I've summarized the solutions. Please reply.

Thank you.

android map

2022-09-22 08:37

1 Answers

To use Geolocation in Webview, you need several settings, such as JavaScript and Geolocation Permissions.Callback.

//set JavaScript to work
webview.getSettings().setJavaScriptEnabled(true);

//Authorize Geolocaion to use
webView.setWebChromeClient(new WebChromeClient() {
 public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
    callback.invoke(origin, true, false);
 }
});


2022-09-22 08:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.