androidgoogle-maps-android-api-2

Google maps API 18.2 - Can I get my shapes to be drawn in front of the buildings again?


When migrating from com.google.android.gms:play-services-maps:18.0.2 to com.google.android.gms:play-services-maps:18.2.0, my shapes suddenly started to appear behind the buildings and road labels, like this:

enter image description here

As you can see, both the lines (solid black, no transparency) and the area (solid green, no transparency) of this polygon is behind the buildings and labels.

Using version 18.0.2 of the library, this was not a problem. The polygon would then look like this:

enter image description here

Is this a bug in the new library version, or is it supposed to be like this? And is so, how can I get my shapes in front of the buildings and labels again? I tried using setZIndex(), but that did not help.


Solution

  • Use the setBuildingsEnabled(boolean) method and set it to false

    There's an existing bug filed in the Google Public Issue tracker about this. And comment #7 states that this is working as intended with a workaround to disable the 3D buildings using the public method setBuildingsEnabled(boolean).

    So in Kotlin, adding the following code to your onMapReady() should fix the issue with the SDK using the LATEST renderer / versions 18.2.0 and up (which uses the LATEST renderer by default. (See for more info: https://developers.google.com/maps/documentation/android-sdk/renderer)

    override fun onMapReady(googleMap: GoogleMap) {
    
            googleMap.setBuildingsEnabled(false)
    
            //..... The rest of the code here .....//
    }
    

    Or you can also use the following in Kotlin:

    override fun onMapReady(googleMap: GoogleMap) {
    
            googleMap.isBuildingEnabled = false
    
            //..... The rest of the code here .....//
    }
    

    This should prevent the overlay from overlapped by buildings again since they were disabled.

    Proof of concept

    NOTE: The Public Issue Tracker is the authoritative source of updates with regards to features/issues like this. So if this workaround does not work for you, I'd suggest that you star and upvote the issue mentioned above. And provide your use case / reason why the workaround discussed here does not suffice. This will help increase the visibility of the issue to the Google's engineers.