最近项目新加了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即可定位