2012-03-30 55 views
1

我有两个MapActivities,并且使用用户当前位置的工程很好。当我尝试创建第二个使用硬编码纬度/经度的MapActivity时,它会在使用MapController来动画或设置缩放时崩溃。我的代码如下:如果没有应用程序崩溃,则无法使用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)的应用程序将运行正常。但是,如果我在离开要么,我得到如下:

http://imgur.com/t3eg7

我拉我的头发...任何知道我做错了吗?

+1

你能不能给我们logcat的错误信息 – Martyn 2012-03-30 15:58:52

回答

2

你的控制器为空,则需要添加一行来实例化它

mapV = (MapView) findViewById(R.id.yellowmapView); 
mControl = mapV.getController(); // < You need to add this line 
+0

你的先生,是一个圣人!我会给你一个upvote,但我还没有足够的声誉。再次感谢! – kbarnes 2012-03-30 16:26:35

相关问题