【问题标题】:How can I disable transit layer on Google Maps?如何禁用谷歌地图上的交通层?
【发布时间】:2019-11-30 09:41:36
【问题描述】:
在 Google 地图中,交通图层默认显示。我希望能够禁用它,就像在谷歌地图应用程序中一样。
我找不到这样做的选项。我已经看到了交通、室内、建筑物的选项,但没有公交或自行车层的选项。
【问题讨论】:
标签:
android
google-maps
google-maps-api-2
【解决方案1】:
它不能被禁用,但可以隐藏起来,见: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.
【解决方案2】:
您可以通过custom map style 隐藏中转层(中转标记)。您可以使用wizard 创建您自己的带有隐藏交通标记的地图样式:
然后将 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.");
}
...
}