Google maps api 3 Can';不要让复选框工作

Google maps api 3 Can';不要让复选框工作,google-maps-api-3,checkbox,filter,markers,Google Maps Api 3,Checkbox,Filter,Markers,我一直在阅读各种帖子,并一直试图通过复选框来控制我的标记(开/关),但没有成功。下面的代码是我迄今为止管理的代码,但不幸的是它仍然不起作用 如有任何想法/帮助,将不胜感激 我已经使用了xml,但是我想使用js/json文件 <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javas

我一直在阅读各种帖子,并一直试图通过复选框来控制我的标记(开/关),但没有成功。下面的代码是我迄今为止管理的代码,但不幸的是它仍然不起作用

如有任何想法/帮助,将不胜感激

我已经使用了
xml
,但是我想使用
js/json
文件

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>    
<script type="text/javascript">
var json = [{
        "Name" : "NER 1",
        "Latitude" : 51.50732,
        "Longitude" : -0.128673,
        "Connect" : "BS123",
        "ChargeR" : "Standard",
        "ConType" : 1,
        "Operator" : "NER",
    },{
        "Name" : "NER 2",
        "Latitude" : 51.506906,
        "Longitude" : -0.126548,
        "Connect" : "BS234",
        "ChargeR" : "Standard",
        "ConType" : 2,
        "Operator" : "NER",
    },{
        "Name" : "SEW 3",
        "Latitude" : 51.508382,
        "Longitude" : -0.129724,
        "Connect" : "BS345",
        "ChargeR" : "Standard",
        "ConType" : 3,
        "Operator" : "SEW",
    },{
        "Name" : "SEW 1",
        "Latitude" : 51.508322,
        "Longitude" : -0.126902,
        "Connect" : "BS123",
        "ChargeR" : "Standard",
        "ConType" : 4,
        "Operator" : "SEW",
    },{
        "Name" : "TAW 2",
        "Latitude" : 51.507841,
        "Longitude" : -0.126066,
        "Connect" : "BS234",
        "ChargeR" : "Standard",
        "ConType" : 2,
        "Operator" : "TAW",
    },{
        "Name" : "TAW 3",
        "Latitude" : 51.50746,
        "Longitude" : -0.12759,
        "Connect" : "BS345",
        "ChargeR" : "Standard",
        "ConType" : 3,
        "Operator" : "TAW",
    },{
        "Name" : "RCR 1",
        "Latitude" : 51.506439,
        "Longitude" : -0.127922,
        "Connect" : "BS234",
        "ChargeR" : "Standard",
        "ConType" : 4,
        "Operator" : "NER",
    },{
        "Name" : "RCR 2",
        "Latitude" : 51.50943,
        "Longitude" : -0.127428,
        "Connect" : "BS234",
        "ChargeR" : "Standard",
        "ConType" : 2,
        "Operator" : "NER",
    }
]
// JavaScript Document
function initialize() {
    var latlng = new google.maps.LatLng(51.508075,-0.127873);
    var myOptions = {
        zoom: 17,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: true,
    };
    var map = new google.maps.Map(document.getElementById("map"),myOptions);    


        var markers = [];
        var categoryIcons = {}
        for (var i = 0; i < json.length; i++) {
          var data = json[i],
            latLng = new google.maps.LatLng(data.Latitude, data.Longitude);
          var marker = new google.maps.Marker({
            position: latLng,
            map : map,
            title : data.Name,
            icon : categoryIcons[data.ConType],
          });    
          // === Store the category and name info as a marker properties ===
          marker.mycategory = data.ConType;
          marker.myname = data.Name;
          marker.myoperator = data.Operator,              
           markers.push(marker);
           // end Looping through the JSON data
           <!-- Map traffic begin -->       
          (function (marker, data) {
                // Attaching a click event to the current marker
                google.maps.event.addListener(marker, 'click', function(e) {}); // end Attaching a click event to the current marker    
            })(marker, data); // end Creating a closure 

            // == shows all markers of a particular category, and ensures the checkbox is checked ==
      function show(category) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].setVisible(true);
          }
        }
        // == check the checkbox ==
        document.getElementById(category+"box").checked = true;
      }

      // == hides all markers of a particular category, and ensures the checkbox is cleared ==
      function hide(category) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].setVisible(false);
          }
        }
        // == clear the checkbox ==
        document.getElementById(category+"box").checked = false;
        // == close the info window, in case its open on a marker that we just hid
        infoBubble.close();
      }

      // == a checkbox has been clicked ==
      function boxclick(box,category) {
        if (box.checked) {
          show(category);
        } else {
          hide(category);
        }
        // == rebuild the side bar
        makeSidebar();
      }

      function myclick(i) {
        google.maps.event.trigger(gmarkers[i],"click");
      } 

        }   
        }
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body onLoad="initialize()">
<div id="map" style="margin-top: 10px; margin-left: auto; margin-right: auto; width: 1000px; height: 650px;"></div>
<div style="margin-top: 10px; margin-left: auto; margin-right: auto; width: 1000px; height: 650px;">
    <input type="checkbox" id="1" class="cas" name="1" value="1" onclick="boxclick(this,'1')" checked/>1<br>
    <input type="checkbox" id="2" class="cas" name="2" value="2" onclick="boxclick(this,'2')" checked/>2<br>
    <input type="checkbox" id="3" class="cas" name="3" value="3" onclick="boxclick(this,'3')" checked/>3<br>
    <input type="checkbox" id="4" class="cas" name="4" value="4" onclick="boxclick(this,'4')" checked/>4
    </div>

var json=[{
“名称”:“NER 1”,
“纬度”:51.50732,
“经度”:-0.128673,
“连接”:“BS123”,
“充电器”:“标准”,
“ConType”:1,
“操作员”:“NER”,
},{
“名称”:“NER 2”,
“纬度”:51.506906,
“经度”:-0.126548,
“连接”:“BS234”,
“充电器”:“标准”,
“ConType”:2,
“操作员”:“NER”,
},{
“名称”:“SEW 3”,
“纬度”:51.508382,
“经度”:-0.129724,
“连接”:“BS345”,
“充电器”:“标准”,
“ConType”:3,
“操作员”:“SEW”,
},{
“名称”:“SEW 1”,
“纬度”:51.508322,
“经度”:-0.126902,
“连接”:“BS123”,
“充电器”:“标准”,
“ConType”:4,
“操作员”:“SEW”,
},{
“名称”:“TAW 2”,
“纬度”:51.507841,
“经度”:-0.126066,
“连接”:“BS234”,
“充电器”:“标准”,
“ConType”:2,
“操作员”:“TAW”,
},{
“名称”:“TAW 3”,
“纬度”:51.50746,
“经度”:-0.12759,
“连接”:“BS345”,
“充电器”:“标准”,
“ConType”:3,
“操作员”:“TAW”,
},{
“名称”:“RCR 1”,
“纬度”:51.506439,
“经度”:-0.127922,
“连接”:“BS234”,
“充电器”:“标准”,
“ConType”:4,
“操作员”:“NER”,
},{
“名称”:“RCR 2”,
“纬度”:51.50943,
“经度”:-0.127428,
“连接”:“BS234”,
“充电器”:“标准”,
“ConType”:2,
“操作员”:“NER”,
}
]
//JavaScript文档
函数初始化(){
var latlng=新的google.maps.latlng(51.508075,-0.127873);
变量myOptions={
缩放:17,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP,
mapTypeControl:true,
};
var map=new google.maps.map(document.getElementById(“map”),myOptions);
var标记=[];
var categoryIcons={}
for(var i=0;i对于(var i=0;i所有函数都是初始化函数的本地函数。要从HTML单击事件中使用,它们需要在全局范围内。gmarkers数组未定义

var gmarkers = [];
function initialize() {
    var latlng = new google.maps.LatLng(51.508075,-0.127873);
    var myOptions = {
        zoom: 17,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: true,
    };
    var map = new google.maps.Map(document.getElementById("map"),myOptions);


    var categoryIcons = {}
    for (var i = 0; i < json.length; i++) {
      var data = json[i],
      latLng = new google.maps.LatLng(data.Latitude, data.Longitude);
      var marker = new google.maps.Marker({
            position: latLng,
            map : map,
            title : data.Name,
            icon : categoryIcons[data.ConType],
      });
      // === Store the category and name info as a marker properties ===
      marker.mycategory = data.ConType;
      marker.myname = data.Name;
      marker.myoperator = data.Operator,
      gmarkers.push(marker);
      // end Looping through the JSON data
      <!-- Map traffic begin -->
      (function (marker, data) {
          // Attaching a click event to the current marker
          google.maps.event.addListener(marker, 'click', function(e) {}); // end Attaching a click event to the current marker
          })(marker, data); // end Creating a closure

      }
} // end of initialize function

// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
  for (var i=0; i<gmarkers.length; i++) {
    if (gmarkers[i].mycategory == category) {
      gmarkers[i].setVisible(true);
    }
  }
  // == check the checkbox ==
  document.getElementById(category+"box").checked = true;
}

// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
  for (var i=0; i<gmarkers.length; i++) {
    if (gmarkers[i].mycategory == category) {
      gmarkers[i].setVisible(false);
    }
  }
  // == clear the checkbox ==
  document.getElementById(category+"box").checked = false;
  // == close the info window, in case its open on a marker that we just hid
  infoBubble.close();
}

// == a checkbox has been clicked ==
function boxclick(box,category) {
  if (box.checked) {
    show(category);
  } else {
    hide(category);
  }
  // == rebuild the side bar
  makeSidebar();
}

function myclick(i) {
  google.maps.event.trigger(gmarkers[i],"click");
}

google.maps.event.addDomListener(window, 'load', initialize);
var-gmarkers=[];
函数初始化(){
var latlng=新的google.maps.latlng(51.508075,-0.127873);
变量myOptions={
缩放:17,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP,
mapTypeControl:true,
};
var map=new google.maps.map(document.getElementById(“map”),myOptions);
var categoryIcons={}
for(var i=0;i对于(var i=0;i)复选框功能应该与“工作”XML版本相同(假设JSON中的信息与XML中的信息相同)。XML代码是什么样子的?您有活版本还是JSFIDLE(这样您就不必把这个问题弄得一团糟)?