I\'m trying to get my map view to return to the normal style when I flick the switch within my fragment to the the OFF position but it\'s not working. The following is what occu
The else of this part:
if(isChecked){
boolean success = mGoogleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e("TabFragmentMap", "Style parsing failed.");
}
}else{
// What goes here?
// mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
You need to uncomment it
else {
// What goes here?
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
In your else
code, you are using setMapType
while you should be using setMapStyle
with a null
parameter to clear the previously set styling, as mentioned here.
Set to null to clear any previous custom styling.
So, your code should go like this:
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
boolean success = mGoogleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e("TabFragmentMap", "Style parsing failed.");
}
}else{
boolean success = mGoogleMap.setMapStyle(null);
if (!success) {
Log.e("TabFragmentMap", "Removing style failed.");
}
}
}
You should also return the Switch
back to its previous checked state in both your if (!success)
conditions and show a Toast
to the users so they can understand what is happening.