如何将它们转换为Java?
HTML:
<head>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<body onload="initialize()">
<div>
<input id="address" type="textbox" value="96818">
<input type="button" value="Geocode" onclick="codeAddress()">
<input id="coord" type="textbox" value="">
</div>
</body>
</html>
JavaScript
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({
'address': address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
$('#coord').val(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
我正在做一个 Android 应用程序项目,我想使用代码从邮政编码获取 LatLng,这样我就可以在 Google map 上显示位置。 请帮助我..
最佳答案
您可以使用WebView来做到这一点。
WebView 是 Android 中的一个小部件,它可以像 Web 浏览器一样显示网站或仅显示 html 文件。 WebView 的核心与 Chrome 相同,因此如果您的网页在 Chrome 中运行良好,那么它在 WebView 中也能运行。
首先,将您的html代码和JS代码放入一个html文件中,然后将其放入您的Android应用程序的“/assets”文件夹中。
以下代码将在屏幕上显示页面,并允许 JS 运行。
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView=new WebView(this);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
String url = "file:///android_asset/test.html";
webView.loadUrl(url);
setContentView(webView);
}
}
关于java - 如何将 HTML/Javascript 代码转换为可用于 Eclipse 中的 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30657050/