android webview支持并获取位置信息

在java文件中设置webview,

WebView webView = (WebView)findViewById(R.id.webview);

WebSettings webSettings = webView.getSettings();

//webview

webSettings.setJavaScriptEnabled(true);

//启用数据库  

webSettings.setDatabaseEnabled(true);    

//设置定位的数据库路径  

String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); 

webSettings.setGeolocationDatabasePath(dir);   

//启用地理定位  

扫描二维码关注公众号,回复: 5491352 查看本文章

webSettings.setGeolocationEnabled(true);  

//开启DomStorage缓存

webSettings.setDomStorageEnabled

webView.setWebChromeClient(new WebChromeClient() {

  @Override

       public void onReceivedIcon(WebView view, Bitmap icon) {

super.onReceivedIcon(view, icon);

}

  @Override
  public void onGeolocationPermissionsShowPrompt(String origin,Callback callback) {

callback.invoke(origin, true, false);  

super.onGeolocationPermissionsShowPrompt(origin, callback);

}

  });


//配置权限

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

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

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

(在某些限制应用定位权限的手机中,,需要开启应用的定位权限,否则会定位失败)


猜你喜欢

转载自blog.csdn.net/u011325156/article/details/51507052