我有两个MapActivities,而使用用户当前位置的MapActivities非常有用。当我尝试创建第二个使用硬编码纬度/经度的MapActivity时,使用MapController动画或设置缩放时会崩溃。我的代码如下:
package com.breckbus.app;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class Yellowroute extends MapActivity {
MapController mControl;
GeoPoint GeoP;
MapView mapV;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.yellowroute);
mapV = (MapView) findViewById(R.id.yellowmapView);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
double lat = 39.482547;
double longi = -106.047699;
GeoP = new GeoPoint((int) (lat * 1E6), (int) (longi * 1E6));
mControl.animateTo(GeoP);
mControl.setZoom(13);
mapV.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
} //end of map.java
如果我取出mControl.animateTo(GeoP)或mControl.setZoom(13),该应用程序将运行良好。但是,如果我离开,我会得到以下内容:
我把头发拉出来...知道我做错了什么?
答案 0 :(得分:2)
您的控制器为空,您需要添加一行来实例化它
mapV = (MapView) findViewById(R.id.yellowmapView);
mControl = mapV.getController(); // < You need to add this line