80,350
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>GeoSurf Maps JavaScript API Example</title>
<script src="http://www.tianditu.com/guide/lib/GeoSurfJSAPI.js"
type="text/javascript"></script>
<script src="http://www.tianditu.com/guide/2d_samples/sampleCfg.js"
type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var map = new GeoSurf.PortalMap("frist_map");
map.loadLayerGroup(vectorGroup);
map.setCenter(new GeoSurf.LonLat(39.92361, 116.3809), 10);
var chinaBounds = new GeoSurf.Bounds(73.30,17,135.65,52.32);
map.zoomToExtent(chinaBounds);
alert("initialize");
}
</script>
<script type="text/javascript">
function testEcho() {
alert("testEcho");
}
</script>
</head>
<body onload="initialize()">
<div id="frist_map" style="width: 500px; height: 300px"></div>
</body>
</html>
package com.TianMap;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.webkit.*;
import android.widget.Button;
import android.widget.Toast;
public class TianMap extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private boolean CheckNetWork() {
Context context = getApplicationContext();
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = cm.getActiveNetworkInfo();
if (network != null) {
return network.isAvailable();
}
else{
return false;
}
}
private void init(){
if(CheckNetWork()){
DisplayMetrics metrics = new DisplayMetrics();
final WebView mWebView= (WebView)findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient() {
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
//Required functionality here
return super.onJsAlert(view, url, message, result);
}});
try{
mWebView.loadUrl("file:///android_asset/demo.html");
mWebView.loadUrl("javascript:testEcho()"); //这句为什么不调用JS函数呢?????
Button mButton = (Button) findViewById(R.id.button1);
//给button添加事件响应,执行JavaScript的fillContent()方法
mButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mWebView.loadUrl("javascript:testEcho()"); //这里的可以调用。。
}
});
Toast.makeText(this, "ooo", Toast.LENGTH_SHORT).show();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
else{
new AlertDialog.Builder(this)
.setMessage("网络链接错误,点击确定退出")
.setPositiveButton("确定",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface, int i){
android.os.Process.killProcess(android.os.Process.myPid());
}
})
.show();
}
}
}