项目中H5网页使用的高德地图定位,好吧,权限授予了还是定位不了
解决:
1.根据谷歌API,开启WebView定位相关API。
2.设置前后对比,设置后可以定位。
完整代码:
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;
/**
* Created by ZP on 2017/4/17.
*/
public class WebViewActivity extends AppCompatActivity {
private WebView mWebView;//webview 控件.用于展示HTML 5页面
private LinearLayout mLlRoot;
private LinearLayout.LayoutParams mLayoutParams;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
initViews();
}
private void initViews() {
mWebView = new WebView(getApplicationContext());
mLlRoot = (LinearLayout) findViewById(R.id.ll_root);
mLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mLlRoot.addView(mWebView, mLayoutParams);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
// settings.setDatabaseEnabled(true);
// settings.setDomStorageEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
super.onGeolocationPermissionsShowPrompt(origin, callback);
}
});
mWebView.loadUrl("file:///android_asset/map.html");
}
}