1

Using this stackoverflow question, I have tried to apply some custom styling to an Android mapview.

The styling is basicly just making the water black

mapstyle_json.js:

[
    {
        featureType: 'water',
        elementType: 'geometry',
        stylers: [{color: '#000000'}]
      },
      {
        featureType: 'water',
        elementType: 'labels.text.fill',
        stylers: [{color: '#515c6d'}]
      },
      {
        featureType: 'water',
        elementType: 'labels.text.stroke',
        stylers: [{color: '#17263c'}]
      }
]

My main activity:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final MapView mapView = (MapView) findViewById(R.id.mapView);
        final android.content.Context context = this;

        mapView.onCreate(savedInstanceState);
        mapView.getMapAsync(new OnMapReadyCallback() {

            @Override
            public void onMapReady(GoogleMap googleMap) {
                googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // Without this line, the styling works as intended
                try {
                    // Customise the styling of the base map using a JSON object defined
                    // in a raw resource file.
                    boolean success = googleMap.setMapStyle(
                            MapStyleOptions.loadRawResourceStyle(
                                    context, R.raw.mapstyle_json));

                    if (!success) {
                        Log.e("1", "Style parsing failed.");
                    }
                } catch (Resources.NotFoundException e) {
                    Log.e("1", "Can't find style. Error: ", e);
                }
                Log.d("1", "onMapReady: something");
                LatLng coordinates = new LatLng(45.832119, 6.865575);
                googleMap.addMarker(new MarkerOptions().position(coordinates).title("hello"));
                googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 12));
                mapView.onResume();
            }
        });
    } 
}

Without setting the map type (using the default map type), styling works as it should. It should be possible to style a TERRAIN type map, given the linked question. (Maybe only with javascript).

Why doesn't this styling get applied to a terrain type map? Is it possible in the Android mapView?

EDIT:

The code is based on google's own guide, with the raw resource use case: https://developers.google.com/maps/documentation/android-sdk/styling

Maybe this is a google API v2 vs v3 issue. As far as I understand, Android uses API v2. The linked issue is about v3

0

1 Answer 1

3

Seems its expected behavior. From Official Documentation:

Styling works only on the normal map type.

Normal map type is:

Typical road map. Shows roads, some features built by humans, and important natural features like rivers. Road and feature labels are also visible.

6
  • It says it like it doesn't work on indoor maps: Styling works only on the normal map type. Styling does not affect indoor maps. What could be a possible workaround? I am thinking something in the lines of creating a javascript view inside my android app Dec 18, 2018 at 12:02
  • @JonasPraem No. "Styling does not affect indoor maps." - other sentence (but I agree - they can wrote it in better maner). Indoor maps is not map type (that can be Normal, Hybrid, Satellite, Terrain and None). Dec 18, 2018 at 12:21
  • 1
    @JonasPraem And IMHO best workaround is to use Tile Overlay that loads normal map tile from Google URLs (like in this question) and set water to black (and other to transparent) on tile bitmap directly. Dec 18, 2018 at 12:34
  • It is possible on a javascript map (see linked issue), which is why this frustrates me. I was also thinking of an opacity overlay, say i just want the whole map more redish - and add an opacity color on top. Maybe doing a javascript view inside my Android application - maybe that is possible for the mapview? Dec 18, 2018 at 12:51
  • @JonasPraem I think everything is possible, but IMHO best workaround is to use Tile Overlay that loads normal map tile... ) Dec 18, 2018 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.