我调用html代码 在Android WebView中载入搜狗地图,地图可以载入但是地图画面是死的,不能拖动?
为什么呢?Html代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Sogou Maps JavaScript API v2 </title>
<style type="text/css">
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#map_canvas{height:100%}
</style>
<script type="text/javascript" src="http://api.go2map.com/maps/js/api_v2.0.js"></script>
<script type="text/javascript">
function initialize() {
var myLatlng = new sogou.maps.LatLng(39.99226610365429,116.32591408950312);
var myOpti** = {
'zoom': 17,
'center': myLatlng,
'mapTypeId': sogou.maps.MapTypeId.ROADMAP
}
var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOpti**);
}
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
java代码:
package sz.student.mu;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class mainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview=(WebView)findViewById(R.id.webview);
webview.setClickable(true);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
// webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webview.loadUrl("file:///android_asset/js.html");
}
}
为什么呢?Html代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Sogou Maps JavaScript API v2 </title>
<style type="text/css">
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#map_canvas{height:100%}
</style>
<script type="text/javascript" src="http://api.go2map.com/maps/js/api_v2.0.js"></script>
<script type="text/javascript">
function initialize() {
var myLatlng = new sogou.maps.LatLng(39.99226610365429,116.32591408950312);
var myOpti** = {
'zoom': 17,
'center': myLatlng,
'mapTypeId': sogou.maps.MapTypeId.ROADMAP
}
var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOpti**);
}
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
java代码:
package sz.student.mu;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class mainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview=(WebView)findViewById(R.id.webview);
webview.setClickable(true);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
// webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webview.loadUrl("file:///android_asset/js.html");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货