Android MapView:animateTo在地图平移时不起作用

时间:2012-04-30 11:43:26

标签: android

以下代码执行以下操作: 选中“焦点”复选框时,地图会动画显示地图中的单个叠加项。 有一个问题: 当我选中复选框时拖动地图以使地图仍在移动时,检查没有视觉效果。 有什么想法吗?

List<Overlay> mapOverlays;
Drawable drawable;
AssetMarkersOverlay itemizedOverlay;
private CheckBox autofocusCheckBox;
MapView mapView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.getController().setZoom(4);
    mapView.setBuiltInZoomControls(true);

    mapOverlays = mapView.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.bubble_blue);
    itemizedOverlay = new AssetMarkersOverlay(drawable);

    String assetName = "TEST";
    int lat = 3;
    int lon = 3;

    ArrayList<GeoPoint> geoPointList = new ArrayList<GeoPoint>();

    GeoPoint point = new GeoPoint(lat, lon);

    autofocusCheckBox = (CheckBox) findViewById(R.id.showInMap);
    autofocusCheckBox.setTag(point);
    autofocusCheckBox
            .setOnCheckedChangeListener(new OnCheckedChangeListener() {

                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                    if (isChecked && buttonView.getTag() != null) {
                        focusAsset((GeoPoint) buttonView.getTag());
                    }
                }
            });

    geoPointList.add(point);
    itemizedOverlay.addOverlay(lat, lon, assetName, assetName);

    mapOverlays = mapView.getOverlays();
    mapOverlays.clear();
    mapView.postInvalidate();
    mapOverlays.add(itemizedOverlay);
    fitPoints(geoPointList, mapView);
    mapView.postInvalidate();

}

private void focusAsset(GeoPoint point) {
    mapView.requestFocus();
    mapView.clearAnimation();
    mapView.getController().stopAnimation(true);
    mapView.getController().setZoom(14);
    mapView.getController().animateTo(point);
    mapView.postInvalidate();
}

1 个答案:

答案 0 :(得分:0)

我使用AsyncTask来修复类似的问题。它有时有效,但不是所有时间。基本上我只是稍微调用animateTo几次延迟。值得注意的是,看起来getMapCenter会返回它动画的位置而不是当前的真实中心,因为我尝试使用它来检测它是否到达新位置并且它在很多时候都不起作用。此外,至少在ICS上似乎没有动画的持续时间超过1000毫秒,因此在拨打电话前可能会等待很长时间才能解决问题。