android中webview支持位置定位

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

android

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);   

//启用地理定位  

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" />

 

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

良心的公众号,更多精品文章,不要忘记关注哈

《Android和Java技术栈》


猜你喜欢

转载自blog.csdn.net/huohu1007/article/details/51423470
今日推荐