我在服务器端使用Google Maps API V3,并在GoogleTV应用程序上加载WebView。在第一次加载时,我的标记图像失真,但如果我使用缩放控件,它会适当地按比例重新加载。我附上了2个屏幕截图:
首次加载(不正确):
放大和缩小(正确);
以下是我的updateView,其中包含中心网址:
private void updateView(){
Log.i(DEBUG_TAG, " updateView()");
// added
mWebView = (WebView)findViewById(R.id.mapWebView);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
Double lat = 0.0;
Double lon = 0.0;
lat = Double.parseDouble(mWd.getCurrentWeatherDataModel().lat);
lon = Double.parseDouble(mWd.getCurrentWeatherDataModel().lon);
final String centerURL = "javascript:mpSetCenter(" + lat + "," + lon + ")";
if (mWebView != null) {
mWebView.getSettings().setBuiltInZoomControls(false);
mWebView.getSettings().setEnableSmoothTransition(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
//mWebView.loadUrl("javascript:setZoomLevel(" + mZoomLevel + ")");
Log.i(DEBUG_TAG, "onPageFinished() b4 dimiss dialogs");
Dialogs.dismiss();
mHandler.removeCallbacks(mRunnable);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mWebView.loadUrl(centerURL);
}
}, 1000);
if (mWd.getCurrentWeatherDataModel().overlayOption.equals(RADAR_OVERLAY)) {
mIsRadarShowing = true;
mIsSatelliteShowing = false;
} else {
mIsRadarShowing = false;
mIsSatelliteShowing = true;
}
init();
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.i(DEBUG_TAG, "Error, oh noes! " + description);
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.i(DEBUG_TAG, "message in onJsAlert is " + message);
result.confirm();
return true;
}
});
mWebView.loadUrl("file:///android_asset/maps_v3.html");
Dialogs.dismiss();
Log.i(DEBUG_TAG, "dismiss b4 this stmnt and showLoadingDialog after");
Dialogs.showLoadingDialog((android.app.Activity) mContext);
mHandler.postDelayed(mRunnable, 30000);
}
}
任何想法为什么?
以下是创建标记的js文件部分:
//Center map on lat/lon of chosen location.
function mpSetCenter(lat, lon) {
var centerPoint = new google.maps.LatLng(lat, lon);
clearMarkers();
map.setCenter(centerPoint);
var marker = new google.maps.Marker({
position: centerPoint,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
map.setCenter(marker.getPosition());
});
marker_list.push(marker);
}