Google地图的夜间模式?

时间:2016-08-28 13:39:16

标签: 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岁了,我想应该有一些改进。

4 个答案:

答案 0 :(得分:16)

Google announced已为AndroidiOS推出自定义地图样式以及新的styling wizard,可让您设计一次样式,并将其应用于支持所有支持的平台:Android,iOS,JavaScript API,甚至是Static Maps API。

Google Maps Android API开发人员文档甚至提供了一个有效的night mode样式示例。使用自定义样式的code sample也可用。

答案 1 :(得分:11)

它很简单只需创建一个原始文件夹并右键单击原始文件夹并在新的选择文件中选择新文件,然后键入文件名,例如: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));

就是这样

答案 2 :(得分:0)

前往:

https://mapstyle.withgoogle.com

创建所需的内容并将json复制到一个.json文件中。将其放在res / raw上,然后使用:

mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.name));

您应该在onMapReady回调上调用上述函数。

答案 3 :(得分:-2)

轻松解决强迫我发现的夜间模式。

  • 转到设置
  • 转到日期和时间
  • 禁用自动日期和时间。
  • 将您的时间设置为晚上7点或更晚。

应该将应用程序设置为夜间模式,您可以在旅行结束后更改时间。

相关问题