Skip to content Skip to sidebar Skip to footer

Is There A Method To Check Whether The Current Map Is In Map Or Satellite Mode?

I am setting the Map to Satellite view on click of a toggle button mapToggle.setOnClickListener(new OnClickListener() { public void onClick(View v) {

Solution 1:

The way I accomplished this is to set an int value in your SharedPreferences. Then onClick of that button, get the value and switch satellite on or off accordingly.

privatestaticfinalintOVERLAY_STREET=0;
privatestaticfinalintOVERLAY_SAT=1;

@OverridepublicvoidonCreate(Bundle savedInstanceState) {

    intcurrentOverlayMode= prefs.getInt("map_viewmode", 0);

    mOverlayModeBtn = (Button)findViewById(R.id.googlemaps_overlay_btn);
    mOverlayModeBtn.setOnClickListener(newOnClickListener() {
        publicvoidonClick(View v) {
            if (currentOverlayMode < 1)
                currentOverlayMode++;
            elsecurrentOverlayMode=0;
            switch (currentOverlayMode) {
            case OVERLAY_STREET:
                mMaps.setSatellite(false);
                mMaps.setStreetView(true);
                prefsEditor.putInt("map_viewmode", OVERLAY_STREET);
                break;
            case OVERLAY_SAT:
                mMaps.setStreetView(false);
                mMaps.setSatellite(true);
                prefsEditor.putInt("map_viewmode", OVERLAY_SAT);
                break;
            }
            prefsEditor.commit();
            mMaps.invalidate();
        }
    });
}

You may want to clean it up a little, but it works for me.

Post a Comment for "Is There A Method To Check Whether The Current Map Is In Map Or Satellite Mode?"