关于Android webview中无法定位的解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kururunga/article/details/84982511

最近项目新加了h5,在h5中调用高德地图api进行定位,但是点进去后定位信息一直获取失败,网上找资料,基本都是这样:
1.权限

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

2.webchromeclient配置:

private class MyWbChromeClient extends WebChromeClient {
        @Override
        public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
            super.onGeolocationPermissionsShowPrompt(origin, callback);
        }

3.webview以及websettings配置:

        wv_content.getSettings().setJavaScriptEnabled(true);
        wv_content.getSettings().setUseWideViewPort(true);
        wv_content.getSettings().setLoadWithOverviewMode(true);
        wv_content.getSettings().setDatabaseEnabled(true);
        String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        wv_content.getSettings().setGeolocationDatabasePath(dir);
        wv_content.getSettings().setDomStorageEnabled(true);
        // 开启 Application Caches 功能
        wv_content.getSettings().setAppCacheEnabled(true);

但是我这样操作完之后还是不能定位,最后将targetsdkversion从27改成23即可定位

猜你喜欢

转载自blog.csdn.net/kururunga/article/details/84982511