ababzy
ababzy

Reputation: 687

Android-Google Maps Satellite toggle

I want to add button which will toggle between normal and satellite view in the map view and I keep getting a the application has stopped unexpectedly error

public class NewMapsActivity extends MapActivity 
{    
    private MapView myMapView;

    @Override
        protected void onCreate(Bundle icicle) 
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        MapView myMapView = (MapView) findViewById(R.id.mapview);

        Button mySatelliteButton = (Button)findViewById(R.id.c_button);
        mySatelliteButton.setOnClickListener(new View.OnClickListener()
        {
           public void onClick(View v)
            {
                SetSatellite();
            }
        });
     myMapView.setBuiltInZoomControls(true);
     }

    private void SetSatellite()
        {
            if ( myMapView.isSatellite() )
                myMapView.setSatellite(false);
            else 
                myMapView.setSatellite(true);
        }

    @Override
        protected boolean isRouteDisplayed() 
     {
            return false;
     }
}

Upvotes: 0

Views: 3148

Answers (1)

deepa
deepa

Reputation: 2494

If everything is given right then check whether nullpointer exception occur in myMapview object. since you have declared at top then inside onCreate you are using MapView mymapView=(MapView) findViewById(R.id.mapview); so when you use mymapview object inside setStallite() it will take only the object which was declare at the top. so try this

  myMapView = (MapView) findViewById(R.id.mapview);

but you to declare myMapview at top as MapView myMapview;

check this if not please post your error in logcat

Upvotes: 1

Related Questions