Google Maps API color stylers not working

旧城冷巷雨未停 提交于 2019-12-12 18:06:36

问题


I'm trying to learn how to use the API, and I'm following the code that's on their site completely but for some reason it just doesn't want to change colour.

The code I'm posting is just copy and pasted from their website but I cannot get it to work, can any one please tell me what I'm doing wrong?

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>maps</title>

    <style>
        html, body {
            height: 100%;
            margin: 0;
            width: 100%;

            }
        #map{
            height: 100%;
            margin: 0;
            width: 100%;
            background-color: red;
            }
    </style>

</head>
<body>

<div id="map"></div>

<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

<script>
var map;
function initialize() {
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(-34.397, 150.644),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map'),
      mapOptions);
}

google.maps.event.addDomListener(window, 'load', initialize);


var styleArray = [
  {
    featureType: "all",
    stylers: [
      { saturation: -80 }
    ]
  },{
    featureType: "road.arterial",
    elementType: "geometry",
    stylers: [
      { hue: "#00ffee" },
      { saturation: 50 }
    ]
  },{
    featureType: "poi.business",
    elementType: "labels",
    stylers: [
      { visibility: "off" }
    ]
  }
];
</script>
</body>
</html>

回答1:


You must apply the style to the map:

var mapOptions = {
        zoom: 8,
        center: new google.maps.LatLng(-34.397, 150.644),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: styleArray
      };


来源:https://stackoverflow.com/questions/17033138/google-maps-api-color-stylers-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!