2012-04-30 26 views
1

下面的代码执行以下操作: 当选中“focus”复选框时,地图会为地图上的单个overlay项目生成动画。 有一个问题: 当我拖动地图,使地图仍然移动时,我检查复选框,检查没有视觉效果。 有什么建议吗?Android MapView:animateTo在地图平移时不起作用

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(); 
} 
+0

找到解决方案有什么好运? – bbodenmiller

回答

0

我使用了一个AsyncTask来解决类似的问题。它有时可用,但并非全部。基本上我只是稍微拖延几次就把animate称为。值得注意的是,它似乎getMapCenter返回它正在动画的位置,而不是当前的真正的中心,因为我试图用它来检测它是否到达新的位置或不是很多时间。此外,至少在ICS上动画的持续时间不会超过1000毫秒,因此在拨打电话之前可能会等待很长时间才能解决您的问题。

相关问题