问题
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