版主求助啊 Android webview中百度地图不显示,空白,在线等
展开全部
下面是要显示的HTML 在百度官方下载的
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;hidden;margin:0;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Ow1yfpNXULSrlf9RVpdtmRuW"></script>
<title>添加普通标注点</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("allmap");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 14);
var marker1 = new BMap.Marker(new BMap.Point(116.384, 39.925)); // 创建标注
map.addOverlay(marker1); // 将标注添加到地图中
//创建信息窗口
var infoWindow1 = new BMap.InfoWindow("普通标注");
marker1.addEventListener("click", function(){this.openInfoWindow(infoWindow1);});
//创建小狐狸
var pt = new BMap.Point(116.417, 39.909);
var myIcon = new BMap.Icon("fox.gif", new BMap.Size(300,157));
var marker2 = new BMap.Marker(pt,{icon:myIcon}); // 创建标注
map.addOverlay(marker2); // 将标注添加到地图中
//让小狐狸说话(创建信息窗口)
var infoWindow2 = new BMap.InfoWindow("<p style='font-size:14px;'>哈哈,你看见我啦!我可不常出现哦!</p><p style='font-size:14px;'>赶快查看源代码,看看我是如何添加上来的!</p>");
marker2.addEventListener("click", function(){this.openInfoWindow(infoWindow2);});
</script>
复制代码
下面是我的activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_biotope);
findViewById();
mWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
//启用数据库
webSettings.setDatabaseEnabled(true);
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
//启用地理定位
webSettings.setGeolocationEnabled(true);
//设置定位的数据库路径
webSettings.setGeolocationDatabasePath(dir);
//最重要的方法,一定要设置,这就是出不来的主要原因
webSettings.setDomStorageEnabled(true);
mWebView.getSettings().setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
mWebView .setScrollbarFadingEnabled( true );
mWebView .setScrollBarStyle(View. SCROLLBARS_INSIDE_OVERLAY );
mWebView.setWebChromeClient(new WebChromeClient(){
//配置权限(同样在WebChromeClient中实现)
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
super.onGeolocationPermissionsShowPrompt(origin, callback);
}
});
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url)
{ // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边
view.loadUrl(url);
return true;
}});
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT | WebSettings.LOAD_CACHE_ELSE_NETWORK);
//0526 cyf update
Map<String,String> map=new HashMap<String,String>();
map.put("shopSid", "109449");
// mWebView.loadUrl(Contant.NEARBY);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// mWebView.loadUrl(Contant.NEARBY);
mWebView.loadUrl("http://192.168.0.105:8080/webjs/test.html");
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light,
R.color.holo_red_light);
}
@Override
protected void findViewById() {
super.findViewById();
mBack = (ImageView)findViewById(R.id.top_back);
mTitle = (TextView)findViewById(R.id.top_title);
mTitle.setText(R.string.tab_nearby);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
super.onClick(v);
switch (v.getId()) {
case R.id.top_back:
finish();
break;
default:
break;
}
}
@Override
public void onRefresh() {
// TODO Auto-generated method stub
mWebView.reload();
swipeLayout.setRefreshing(false);
}
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;hidden;margin:0;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Ow1yfpNXULSrlf9RVpdtmRuW"></script>
<title>添加普通标注点</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("allmap");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 14);
var marker1 = new BMap.Marker(new BMap.Point(116.384, 39.925)); // 创建标注
map.addOverlay(marker1); // 将标注添加到地图中
//创建信息窗口
var infoWindow1 = new BMap.InfoWindow("普通标注");
marker1.addEventListener("click", function(){this.openInfoWindow(infoWindow1);});
//创建小狐狸
var pt = new BMap.Point(116.417, 39.909);
var myIcon = new BMap.Icon("fox.gif", new BMap.Size(300,157));
var marker2 = new BMap.Marker(pt,{icon:myIcon}); // 创建标注
map.addOverlay(marker2); // 将标注添加到地图中
//让小狐狸说话(创建信息窗口)
var infoWindow2 = new BMap.InfoWindow("<p style='font-size:14px;'>哈哈,你看见我啦!我可不常出现哦!</p><p style='font-size:14px;'>赶快查看源代码,看看我是如何添加上来的!</p>");
marker2.addEventListener("click", function(){this.openInfoWindow(infoWindow2);});
</script>
复制代码
下面是我的activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_biotope);
findViewById();
mWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
//启用数据库
webSettings.setDatabaseEnabled(true);
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
//启用地理定位
webSettings.setGeolocationEnabled(true);
//设置定位的数据库路径
webSettings.setGeolocationDatabasePath(dir);
//最重要的方法,一定要设置,这就是出不来的主要原因
webSettings.setDomStorageEnabled(true);
mWebView.getSettings().setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
mWebView .setScrollbarFadingEnabled( true );
mWebView .setScrollBarStyle(View. SCROLLBARS_INSIDE_OVERLAY );
mWebView.setWebChromeClient(new WebChromeClient(){
//配置权限(同样在WebChromeClient中实现)
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
super.onGeolocationPermissionsShowPrompt(origin, callback);
}
});
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url)
{ // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边
view.loadUrl(url);
return true;
}});
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT | WebSettings.LOAD_CACHE_ELSE_NETWORK);
//0526 cyf update
Map<String,String> map=new HashMap<String,String>();
map.put("shopSid", "109449");
// mWebView.loadUrl(Contant.NEARBY);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// mWebView.loadUrl(Contant.NEARBY);
mWebView.loadUrl("http://192.168.0.105:8080/webjs/test.html");
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light,
R.color.holo_red_light);
}
@Override
protected void findViewById() {
super.findViewById();
mBack = (ImageView)findViewById(R.id.top_back);
mTitle = (TextView)findViewById(R.id.top_title);
mTitle.setText(R.string.tab_nearby);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
super.onClick(v);
switch (v.getId()) {
case R.id.top_back:
finish();
break;
default:
break;
}
}
@Override
public void onRefresh() {
// TODO Auto-generated method stub
mWebView.reload();
swipeLayout.setRefreshing(false);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询