我在哪里向Google Maps Javascript添加JSON?

我在哪里向Google Maps Javascript添加JSON?,javascript,json,google-maps,Javascript,Json,Google Maps,我有谷歌地图的脚本: <script type="text/javascript"> function initialize() { var mapOptions = { center: new google.maps.LatLng(51.523612, -0.125816), zoom: 17, }; var map = new google.maps.Map(document.g

我有谷歌地图的脚本:

<script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(51.523612, -0.125816),
          zoom: 17,

        };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
</script>
如何将它们结合起来,形成我想要的风格

我似乎找不到正确的文档。

下面是一个示例,演示如何将各种元素集成在一起

  var styles =   [
    {
      stylers: [
        { hue: '#00ffe6' },
        { saturation: -20 }
      ]
    },{
      featureType: 'road',
      elementType: 'geometry',
      stylers: [
        { lightness: 100 },
        { visibility: 'simplified' }
      ]
    },{
      featureType: 'road',
      elementType: 'labels',
      stylers: [
        { visibility: 'off' }
      ]
    }
  ];

  // Create a new StyledMapType object, passing it the array of styles,
  // as well as the name to be displayed on the map type control.
  var styledMapType = new google.maps.StyledMapType(styles,
    {name: 'Styled Map'});

  // Create a map object, and include the MapTypeId to add
  // to the map type control.
  var mapOptions = {
    zoom: 12,
    center: new google.maps.LatLng(50.9818, -114.1219),
    mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP,
        google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID,
        google.maps.MapTypeId.TERRAIN, 'styled_maps']
    }
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);

  // Associate the styled map with the MapTypeId and set it to display.
  map.mapTypes.set('styled_maps', styledMapType);
  map.setMapTypeId('styled_maps');
}

在我看来,这个JSON描述了映射选项,所以它应该包含在mapOptions变量中。您是否尝试过此操作?此外,正在初始化mapOptions变量,该变量的末尾有一个逗号(在zoom=17之后),除非您打算在其后写入内容,否则应将其删除。可能的重复项
  var styles =   [
    {
      stylers: [
        { hue: '#00ffe6' },
        { saturation: -20 }
      ]
    },{
      featureType: 'road',
      elementType: 'geometry',
      stylers: [
        { lightness: 100 },
        { visibility: 'simplified' }
      ]
    },{
      featureType: 'road',
      elementType: 'labels',
      stylers: [
        { visibility: 'off' }
      ]
    }
  ];

  // Create a new StyledMapType object, passing it the array of styles,
  // as well as the name to be displayed on the map type control.
  var styledMapType = new google.maps.StyledMapType(styles,
    {name: 'Styled Map'});

  // Create a map object, and include the MapTypeId to add
  // to the map type control.
  var mapOptions = {
    zoom: 12,
    center: new google.maps.LatLng(50.9818, -114.1219),
    mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP,
        google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID,
        google.maps.MapTypeId.TERRAIN, 'styled_maps']
    }
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);

  // Associate the styled map with the MapTypeId and set it to display.
  map.mapTypes.set('styled_maps', styledMapType);
  map.setMapTypeId('styled_maps');
}