我是一名 Android 开发人员,对 JScript/Jquery/Phonegap 等一无所知。我找到了一个示例,并将其网页替换为我的。在我的网页中,我有一个 java 脚本如下:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">var map;function initialize()
{
var mapDiv = document.getElementById('map-canvas');
map = new google.maps.Map(mapDiv, {center: new google.maps.LatLng(9.0000,-79.5000),zoom: 13,mapTypeId: google.maps.MapTypeId.SATELLITE});
google.maps.event.addListenerOnce(map, 'tilesloaded', addMarkers);}function addMarkers()
{
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
var latLng = new google.maps.LatLng(9.0000,-79.5000);
var marker = new google.maps.Marker({position: latLng,map: map});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我想使用我的 android 代码动态更改 Lat-Long 值。请有人指导我这样做。
这些是在 web 视图上加载 html 页面的 android 代码。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebViewClient(new NewsClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadUrl("file:///android_asset/www/map.html");
}
private class NewsClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("URL: " + url);
view.loadUrl("javascript:changeLocation('" + url + "')");
return true;
}
}