如何禁用 Google 地图上的交通图层?

How can I disable transit layer on Google Maps?

在Google 地图中,默认显示交通层。我希望能够禁用它,就像在 Google 地图应用程序中一样。

我找不到这样做的选项。我看到了交通、室内、建筑物的选项,但没有交通或自行车层的选项。

无法禁用,但可以隐藏,参见:Hiding Map Features with Styling

您只需要找出 featureType 的样式...

transit                 // selects all transit stations and lines.
transit.line            // selects transit lines.
transit.station         // selects all transit stations.
transit.station.airport // selects airports.
transit.station.bus     // selects bus stops.
transit.station.rail    // selects rail stations.

您可以通过 custom map style. You can use wizard 隐藏交通图层(交通标记)以使用隐藏的交通标记创建您自己的地图样式:

然后 copy-paste JSON 进入 map_style.xml 文件到项目的 raw 文件夹:

然后将地图样式应用于您的地图:

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

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

        if (!success) {
            Log.e(TAG, "Style parsing failed.");
        }
    ...
}