繁体   English   中英

Google地图的夜间模式?

[英]Night mode for Google maps?

我的问题很简单。 谷歌地图有夜间模式吗? 到目前为止,我只能申请GoogleMap.MAP_TYPE_NORMAL | GoogleMap.MAP_TYPE_TERRAIN | GoogleMap.MAP_TYPE_SATELLITE但无法找到夜间模式 我想要这样的东西 在此输入图像描述

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

碰到这篇文章,但它已经2岁了,我想应该有一些改进。

谷歌刚刚宣布推出针对AndroidiOS的自定义地图样式以及一个新的样式向导 ,允许您设计一次样式,并在所有支持的平台上全面应用:Android,iOS,JavaScript API甚至Static Maps API 。

Google Maps Android API开发人员文档甚至提供了工作夜间模式样式示例。 还提供使用自定义样式的代码示例

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

而已

前往 :

https://mapstyle.withgoogle.com

创建你需要的东西复制json将它保存在.json文件中。将它放在res / raw上然后使用:

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

你应该在onMapReady回调上调用上面的函数。

我发现强制夜间模式的简易解决方案。

  • 前往设置
  • 去日期和时间
  • 禁用自动日期和时间。
  • 把你的时间设置为晚上7点或更晚。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM