我无法使用JavaScript函数从bart.gov XML获取时间和目的地?

时间:2014-01-04 16:19:33

标签: javascript php xml api google-maps

我正在使用谷歌地图模拟着名的bart BAY AREA RAPID TRANSIT路线的网站...我制作了一个java脚本,它具有我的所有功能并在我的“index.php”中使用它..并创建了另一个“connection.php”文件,该文件创建了cUrl会话以获取bart网页的信息,它看起来像这样:

<?php

$site = "http://api.bart.gov/api/etd.aspx?cmd=etd&orig=RICH&key=MW9S-E7SL-26DU-VV8V";

$ch = curl_init($site); // Initialize a cURL session

curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$xml = curl_exec($ch);

header("Content-Type: text/xml");
echo $xml;
curl_close($ch);

&GT;

这是我用来从bart的xml文件中获取所需数据的函数:

function getTimes(marker, station, name, infowindow){
alert(station);
var times = [];
jQuery.get("connection.php", {}, function (data){
    $(data).find("station").each(function (){
         var $each = jQuery(this);
         var abrv = $each.find("abbr").text();

         if(station == abrv){                
             $each.find("etd").each(function (){
                 var that = jQuery(this);
                 var destino = that.find("destination").text();
                 var time = that.find("estimate").text();
                 alert(destino);
                 alert(times);
                 times.push(time);
                 destinos.push(destino);
                 infowindow.setContent(time + destino);
                infowindow.open(map, marker);                     
             });
             var contentString ='<h2>' + name + '</h2>';
             for(var i = 0; i < times.length; i++){
                contentString += '<tr>  <td>' + times[i] + ' </td><td> ' + destinos[i] + '</td></tr></br></br>'

             }
             infowindow.setContent(contentString);
             infowindow.open(map, marker);
         }

    });
});

}

不幸的是,它只显示了车站的缩写,它没有显示估计和目的地......有什么不对?我想我已经实现了应有的一切!

0 个答案:

没有答案