-1

这是我的代码。我从 xml 获取数据。但它不起作用..请看看哪里有错误。
我找不到它..我正在研究它一个多星期...

但什么都没有:(

PS对不起我的英语..

这是我的 XML 数据..

 <marker>
<line id_line="1" colour="#ccc" width="4" users="line" coordinats="47.828979,40.974844;47.839451,40.985211;47.848377,40.981064;47.853699,40.984822">
<point lng="40.974844" lat="47.828979"/>
<point lng="40.985211" lat="47.839451"/>
<point lng="40.981064" lat="47.848377"/>
<point lng="40.984822" lat="47.853699"/>
</line>
</marker>

JavaScript:

function line() {
            var point=[];
            downloadUrl("line.php", function(data) {
        var xml = data.responseXML;
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");                             
        var lines = xmlDoc.documentElement.getElementsByTagName("line");
        for (var a = 0; a < lines.length; a++) {
        var colour = lines[a].getAttribute("colour");
        var width  = parseFloat(lines[a].getAttribute("width"));
        var points = lines[a].getElementsByTagName("point");

  alert (points[i].getAttribute("lat"));

 var pts = [];
            for (var i = 0; i < points.length; i++) {
               pts[i] = new google.maps.LatLng(parseFloat(points[i].getAttribute("lat")),
                                   parseFloat(points[i].getAttribute("lng")));
            }
            new google.maps.Polyline(pts,colour,width);
            pts.setMap(map);
          }




  google.maps.event.addListener(pointpath,'mouseover', function() {


        this.setOptions({strokeColor: '#3ADF00' });
           this.setOptions({strokeOpacity: 1.0 });
           this.setOptions({strokeWeight: 4 });
  });

     google.maps.event.addListener(pointpath,'mouseout', function() {


        this.setOptions({strokeColor: '#FF0040' });
           this.setOptions({strokeOpacity: 1.0 });
           this.setOptions({strokeWeight: 2 });
  });




       var mpenc = new google.maps.InfoWindow();
  var contentString = "Status: " + status ;
  google.maps.event.addListener(pointpath,'click', function(event) {
    mpenc.setContent(contentString);
    mpenc.setPosition(event.latLng);
    mpenc.open(map);
  });

 }

     });  
    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }
}
4

1 回答 1

1

xmlDoc 应该是什么?

    var xml = data.responseXML;
    var markers = xmlDoc.documentElement.getElementsByTagName("marker");                             
    var lines = xmlDoc.documentElement.getElementsByTagName("line");

看起来像这一行:

    var xml = data.responseXML;

应该:

    var xmlDoc = data.responseXML;

如果这没有帮助,请参阅Google Maps API v3 文档中的本教程、 “使用 PHP 输出 XML”部分以及有关检查 XML 输出是否有效的部分。

确保你有这一行:

header("Content-type: text/xml");

并且标头包含正确的内容类型。在浏览器中打开 XML 和/或通过验证器运行它(如果 XML 无效,requestXML 将为空)。

稍微修改 xml 的示例

于 2013-02-06T19:00:16.767 回答