将Google Maps API向导中的JSON合并到现有的html中

时间:2013-06-10 17:31:02

标签: json api google-maps-api-3

我正在尝试自定义Google融合表的基本地图。我正在使用Maps API样式向导并创建了我想要的地图,但是我不知道如何将Map向导生成的JSON代码合并到现有页面的html代码中:

这是我要自定义的地图:http://shatterbe.lt/ses_maps/per_capita_upper_eastside.html

这是API Map向导给我的代码:

[
  {
    "stylers": [
      { "visibility": "simplified" }
    ]
  },{
    "featureType": "road.highway",
    "stylers": [
      { "visibility": "off" }
    ]
  }
]

有人帮忙吗?我知道答案可能很简单,但我对这一切都是新手!

1 个答案:

答案 0 :(得分:0)

这对我有用:

function initialize() {
  var map = new google.maps.Map(document.getElementById('googft-mapCanvas'), {
    center: new google.maps.LatLng(25.826923725271442, -80.18369569667362),
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend'));

  layer = new google.maps.FusionTablesLayer({
    map: map,
    styles: [
       {
         "stylers": [
           { "visibility": "simplified" }
         ]
       },{
        "featureType": "road.highway",
         "stylers": [
          { "visibility": "off" }
         ]
       }
    ],
    heatmap: { enabled: false },
    query: {
      select: "col6",
      from: "1_atSM8PGxxDThZlVGvFw4WlyaYHKuXU9CoCvGU0",
      where: ""
    },
    options: {
      styleId: 2,
      templateId: 2
    }
  });
}

Documentation describing how to add styling to the map

Example from the documentation