android - 谷歌地图的夜间模式?

标签 android google-maps-android-api-2 android-maps

我的问题很简单。谷歌地图有夜间模式吗?到目前为止,我只能申请 GoogleMap.MAP_TYPE_NORMAL | GoogleMap.MAP_TYPE_TERRAIN | GoogleMap.MAP_TYPE_SATELLITE 但找不到夜间模式。我想要这样的东西enter image description here

不要建议我使用叠加层,我已经尝试过了。我不能使用它,因为我必须在上面放置标记。

遇到了this帖子,但它已经 2 岁了,我想应该会有一些改进。

最佳答案

它很简单,只需创建一个原始文件夹并右键单击原始文件夹并在该新选择文件中选择新然后键入文件名 eg:map_in_night 然后在显示不同格式后单击确定不要混淆您只需选择 json 并单击确定 并在该 json 文件中添加以下代码

[
  {
    "featureType": "all",
    "elementType": "geometry",
    "stylers": [
      {
        "color": "#242f3e"
      }
    ]
  },
  {
    "featureType": "all",
    "elementType": "labels.text.stroke",
    "stylers": [
      {
        "lightness": -80
      }
    ]
  },
  {
    "featureType": "administrative",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#746855"
      }
    ]
  },
  {
    "featureType": "administrative.locality",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#d59563"
      }
    ]
  },
  {
    "featureType": "poi",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#d59563"
      }
    ]
  },
  {
    "featureType": "poi.park",
    "elementType": "geometry",
    "stylers": [
      {
        "color": "#263c3f"
      }
    ]
  },
  {
    "featureType": "poi.park",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#6b9a76"
      }
    ]
  },
  {
    "featureType": "road",
    "elementType": "geometry.fill",
    "stylers": [
      {
        "color": "#2b3544"
      }
    ]
  },
  {
    "featureType": "road",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#9ca5b3"
      }
    ]
  },
  {
    "featureType": "road.arterial",
    "elementType": "geometry.fill",
    "stylers": [
      {
        "color": "#38414e"
      }
    ]
  },
  {
    "featureType": "road.arterial",
    "elementType": "geometry.stroke",
    "stylers": [
      {
        "color": "#212a37"
      }
    ]
  },
  {
    "featureType": "road.highway",
    "elementType": "geometry.fill",
    "stylers": [
      {
        "color": "#746855"
      }
    ]
  },
  {
    "featureType": "road.highway",
    "elementType": "geometry.stroke",
    "stylers": [
      {
        "color": "#1f2835"
      }
    ]
  },
  {
    "featureType": "road.highway",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#f3d19c"
      }
    ]
  },
  {
    "featureType": "road.local",
    "elementType": "geometry.fill",
    "stylers": [
      {
        "color": "#38414e"
      }
    ]
  },
  {
    "featureType": "road.local",
    "elementType": "geometry.stroke",
    "stylers": [
      {
        "color": "#212a37"
      }
    ]
  },
  {
    "featureType": "transit",
    "elementType": "geometry",
    "stylers": [
      {
        "color": "#2f3948"
      }
    ]
  },
  {
    "featureType": "transit.station",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#d59563"
      }
    ]
  },
  {
    "featureType": "water",
    "elementType": "geometry",
    "stylers": [
      {
        "color": "#17263c"
      }
    ]
  },
  {
    "featureType": "water",
    "elementType": "labels.text.fill",
    "stylers": [
      {
        "color": "#515c6d"
      }
    ]
  },
  {
    "featureType": "water",
    "elementType": "labels.text.stroke",
    "stylers": [
      {
        "lightness": -20
      }
    ]
  }
]

在 onMapReady 中添加

mMap = googleMap;  
mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_night));

就是这样

关于android - 谷歌地图的夜间模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39191867/

相关文章:

android - Google map v2 的自定义信息窗口

适用于不同产品风格的 Android Google Maps API key

android - Google Map Android API V2 和 Google Place API 的使用限制说明

Android - map 无法显示

android - 从 GeoPoints 创建 GPX 文件

Android 双击,ontouchevent 不工作

java - 安卓交互器测试

android - 为什么android :colorBackground work?没有

android - 点击通知启动 Activity 两次

添加权限后 Android list 文件中断