开发者

Can not display map in android

I have 2 activities. In one activity, I have a button. In the click event of that button, I want to open a map in a new activity. But I have no clue why I am having error when I click the button. It says:

application has stopped unexpectedly, please try again.

This is my button click event:

Button btnDrive=(Button)findViewById(R.id.btnDrive);
btnDrive.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent myIntent=new Intent(v.getContext()开发者_开发问答,WebiMapActivity.class);
            startActivityForResult(myIntent,0);             
        }
    });

This is my map activity:

public class WebiMapActivity extends MapActivity{
    private MapView mapView;
    private MapController mapController;

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);
        mapView = (MapView)findViewById(R.id.map_view);
        mapView.setStreetView(true);
        mapView.displayZoomControls(true);
        mapController=mapView.getController();  
    }
}

N.B: I have permission for internet in manifest.xml.


Also, make sure that you have the following line inside the application element of your manifest.xml file:

<uses-library android:name="com.google.android.maps"/>

But as the other stackers have said, post your logcat file showing the exception raised.


public class your_class extends Activity {

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

    //setup button listener
    Button button = (Button)findViewById(R.id.button);
    startButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startYourActivity();                
        }           
    });

    }
    private void startYourActivity() {
    Intent yourIntent = new Intent(this, secondActivity.class);
    startActivity(yourIntent);
}

Hope this will help you : )


Make sure you have mentioned your map API key in your XML file. I think that's the reason your getting tiles and not the map.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜