Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give dark tint to Google Maps in Android

I am using Google Maps in my Android app, I want to give maps a little tint, it is too bright. I tried using another box but the markers also get tinted too, I want only the map to have a slightly dark color and the markers to be bright.

Code-

Box(
    modifier = Modifier
        .fillMaxSize()
        .padding(contentPadding)
) {
    GoogleMap(
        modifier = Modifier.fillMaxSize(),
        googleMapOptionsFactory = {
            GoogleMapOptions().mapId(MapDefaults.mapId)
        },
        cameraPositionState = cameraPositionState,
        properties = style.mapProperties,
        uiSettings = style.mapUiSettings,
        onMapLoaded = {
            onMapLoaded()
        }
    ) {
       //Markers
    }

}

Like this in FlightRadar24 map-

only the map has dark tint, markers are bright.

enter image description here

If I use Night mode then whole map gets dark-

enter image description here

Same for Dark mode -

enter image description here

But in FlightRadar24 the background map is a normal type with a light black cover. How can I get that?

like image 388
Pawandeep Singh Avatar asked Nov 17 '25 17:11

Pawandeep Singh


1 Answers

As Shreyas P said you can do it simply using JSON, here is a full step by step approach to style the Google Map.

Step 1. Create a JSON Style File

  • Create a new file named map_style.json.
  • Add the following content to it for a dark theme:
[
  {
    "elementType": "geometry",
    "stylers": [
      {
        "color": "#212121"  // Dark color for geometry
      }
    ]
  },
  {
    "elementType": "labels.icon",
    "stylers": [
      {
        "visibility": "off"  // Hide icons
      }
    ]
  },
  {
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#757575"  // Light grey color for text
      }
    ]
  },
  {
    "elementType": "labels.text.stroke",
    "stylers": [
      {
        "color": "#212121"  // Dark background for text labels
      }
    ]
  }
]

If you want full description that how the JSON is made click here.

Step 2. Load the JSON in Your Code

  • Place the JSON file into res/raw directory.
  • Use MapStyleOptions.loadRawResourceStyle() to load the JSON style using Shreyas P's method.
val context = LocalContext.current

val mapProperties = remember {
    MapProperties(
        mapStyleOptions = MapStyleOptions.loadRawResourceStyle(context, R.raw.map_style)
    )
}

Box(
    modifier = Modifier
        .fillMaxSize()
        .padding(contentPadding)
) {
    GoogleMap(
        modifier = Modifier.fillMaxSize(),
        googleMapOptionsFactory = {
            GoogleMapOptions().mapId(MapDefaults.mapId)
        },
        cameraPositionState = cameraPositionState,
        properties = mapProperties,
        uiSettings = style.mapUiSettings,
        onMapLoaded = {
            onMapLoaded()
        }
    ) {
       // Markers remain unaffected by the map style
    }
}

I hope it's helpful

like image 161
Umang Thakkar Avatar answered Nov 20 '25 07:11

Umang Thakkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!