0

My Google Map has suddenly stopped working despite me not making any changes to the code and I cannot work out why.

The map.js I am using is:

 var geocoder;
    var map; 
    var marker;
    var layers = [];

  function initialize() {
    geocoder = new google.maps.Geocoder ();
    var latlng = new google.maps.LatLng (50.31697, -3.670807);
    var myOptions = {
      zoom: 10,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
        }
      map = new google.maps.Map(document.getElementById("map-container"),
        myOptions);
      marker = new google.maps.Marker({map:map});

      layers[100] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/100.kml', {preserveViewport: true});
      layers[200] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/200.kml', {preserveViewport: true});
      layers[300] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/boundaryline.kml', {preserveViewport: true});




      layers[0] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/beta0.kml', {preserveViewport: true});
      layers[1] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/beta1.kml', {preserveViewport: true});
      layers[2] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/beta2.kml', {preserveViewport: true});
      layers[10] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/beta10.kml', {preserveViewport: true});
      layers[11] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/beta11.kml', {preserveViewport: true});
       layers[18] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/alpha18.kml', {preserveViewport: true});
       layers[19] = new google.maps.KmlLayer'http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/19/doc.kml', {preserveViewport: true});
      layers[20] = new google.maps.KmlLayer'http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/20/doc.kml', {preserveViewport: true});
      layers[21] = new google.maps.KmlLayer'http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/21/doc.kml', {preserveViewport: true});
     layers[22] = new google.maps.KmlLayer'http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/22/doc.kml', {preserveViewport: true});
    layers[23] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/23/doc.kml', {preserveViewport: true});
      layers[24] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/24/doc.kml', {preserveViewport: true});
      layers[25] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/25/doc.kml', {preserveViewport: true});
      layers[26] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/26/doc.kml', {preserveViewport: true});
      layers[46] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/holbeton.kml', {preserveViewport: true});
      for (var i = 1; i < layers.length; i++) {
      }
        }
    function codeAddress () {
        var address = document.getElementById ("address").value;
        geocoder.geocode ( { 'address': address}, function(results, status)  {
        if (status == google.maps.GeocoderStatus.OK)  {
            map.setCenter(results [1].geometry.location);
            marker.setPosition(results [1].geometry.location);
            map.setZoom(14);
            } 
        else {
            alert("Geocode was not successful for the following reason: " + status);
                }
    }); 
    }

    function toggleLayer(i) {
      if(layers[i].getMap() === null) {
        layers[i].setMap(map);
      }
      else {
        layers[i].setMap(null);
      }
    }
      google.maps.event.addDomListener(window, 'load', initialize);

The only thing I could think of was if the dimensions of the map container were not defined, but these have not been changed and were working fine before.

4

1 回答 1

1

当我打开您的页面时,我的浏览器 (Chrome) 显示 javascript 错误:

未捕获的 SyntaxError:意外的字符串

在这条线上:

layers[19] = new google.maps.KmlLayer'http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/19/doc.kml', {preserveViewport: true});

它应该是:

layers[19] = new google.maps.KmlLayer('http://www.southdevonaonb.org.uk/cordialemapping/kmzdata/withtiledoverlays/19/doc.kml', {preserveViewport: true});

你似乎失去了一个“(”。很难看出如果没有人改变它怎么会发生。

于 2013-05-06T00:43:08.923 回答