Styling Google Map in Android
Asked Answered
N

5

7

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?

Newlywed answered 29/7, 2013 at 18:16 Comment(0)
C
24

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/

Clodhopper answered 30/9, 2016 at 1:43 Comment(2)
Brilliant! Thank you for the code example. works perfectly.Bennink
I used some map style in my app, all of them works except one that dont show interest points(icon and label) in android.i cheked it in mapstyle site and it work in web whtas problem? pastebin.com/yt62rKtmFrerichs
E
7

Yes, now u can declare a Json object to style ur map with GoogleMap.setMapStyle() function. Check the docs.

Enchantress answered 24/9, 2016 at 17:7 Comment(0)
P
6

As per the Google Geo developer advocate Mano Marks, Ingress doesn't use Google Maps and at the current moment, unlike the Javascript API, Android API (via Google Play services) doesn't support styled maps although it does support titles (see TilesProvider etc).

I am hoping they bring the styled maps to Android (Google Play services) soon.

Purity answered 7/8, 2013 at 1:5 Comment(1)
You can track the feature request here.Rhizogenic
L
2

Google just released it a new google maps styling API: https://developers.google.com/maps/documentation/android-api/styling

Lurette answered 22/9, 2016 at 6:42 Comment(0)
H
0

Use Maps Platform Styling Wizard to export standard styles json, you could also validate your style with import option as well - https://mapstyle.withgoogle.com/

Hermaherman answered 14/8, 2021 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.