Styling Google Map in Android

user2631378 picture user2631378 · Jul 29, 2013 · Viewed 20.2k times · Source

I think I know the answer to this, but can we style a Google Map v2? By style, I mean like using the Google Maps API Styled Map Wizard (http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html) that can be used to pull JSON styling data for the JavaScript API.

Google seems to have pulled it off for Ingress, so hoping there's a way. I can't seem to find a way so I suspect Google is using inside knowledge for Ingress. Anyone know for sure?

Answer

Jovis Joseph picture Jovis Joseph · Sep 30, 2016

To style your map, call GoogleMap.setMapStyle() passing a MapStyleOptions object that contains your style declarations in JSON format. You can load the JSON from a raw resource or a string,in you mapReady() function ... so after ading he json call your map ready function will almost look like

 @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        try {
            // Customise the styling of the base map using a JSON object defined
            // in a raw resource file.
            boolean success = mMap.setMapStyle(
                    MapStyleOptions.loadRawResourceStyle(
                            this, R.raw.style_json));

            if (!success) {
                Log.e("MapsActivityRaw", "Style parsing failed.");
            }
        } catch (Resources.NotFoundException e) {
            Log.e("MapsActivityRaw", "Can't find style.", e);
        }
    }

Define a raw resource in /res/raw/style_json.json, containing the JSON style declaration for night-mode styling

You could get the json from the following Link https://mapstyle.withgoogle.com/