Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling Google Map in Android

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?

like image 284
user2631378 Avatar asked Jul 29 '13 18:07

user2631378


People also ask

How do I customize a Google map style?

In the Google Cloud Console, go to the Map Styles page. Select the style you want, and click Customize Style.


1 Answers

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/

like image 99
Jovis Joseph Avatar answered Oct 23 '22 19:10

Jovis Joseph