开发者

Is there a method to check whether the current Map is in Map or Satellite mode?

I am sett开发者_如何学Pythoning the Map to Satellite view on click of a toggle button

 mapToggle.setOnClickListener(new OnClickListener()
     {

         public void onClick(View v)
         {
             if (mapToggle.isChecked())
             {   
                 mapV.setSatellite(true);  

             } else {   
                 mapV.setSatellite(false);  
             }   
    }});

I want to programitically determine which mode it is in when the app restarts. Please advice.


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.

private static final int OVERLAY_STREET = 0;
private static final int OVERLAY_SAT = 1;

@Override
public void onCreate(Bundle savedInstanceState) {

    int currentOverlayMode = prefs.getInt("map_viewmode", 0);

    mOverlayModeBtn = (Button)findViewById(R.id.googlemaps_overlay_btn);
    mOverlayModeBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (currentOverlayMode < 1)
                currentOverlayMode++;
            else
                currentOverlayMode = 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜