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

試著忘記壹切 提交于 2019-12-24 21:43:37

问题


I am setting 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.


回答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.

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.



来源:https://stackoverflow.com/questions/7506969/is-there-a-method-to-check-whether-the-current-map-is-in-map-or-satellite-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!