这是一个php+google map的项目,代码我是仿照google map文档中的例子写的,大意是
第一个html文件从界面中读取输入,传参数到第二个php文件,php文件用mysql查询生成xml文件,供google map画图用。现在不知道哪里有问题,关键是我不知道怎么调试……我装了zend studio,htm中根本没法设断点的,哪位能告诉我程序哪里有问题?或者告诉我怎么调试也行<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps AJAX + MySQL/PHP Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxTPZYElJSBeBUeMSX5xXgq6lLjHthSAk20WnZ_iuuzhMt60X_ukms-AUg" 
            type="text/javascript"></script>
     <script type="text/javascript">function draw()
{
 if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
         map.setCenter(new GLatLng(30.275367,120.134317), 13);
         map.setUIToDefault();
      
var taxiid = document.getElementById("taxiid").value;
        var speedlow = document.getElementById("speedlow").value;
var speedhigh = document.getElementById("speedhigh").value;
var datefrom = document.getElementById("datefrom").value;
var dateto = document.getElementById("dateto").value;
var timefrom = document.getElementById("timefrom").value;
var timeto = document.getElementById("timeto").value;
var url = "phpsql.php?taxiid=" + taxiid + "&speedlow=" + speedlow +
        "&speedhigh=" + speedhigh + "&datefrom=" + datefrom + "&dateto=" + dateto
        + "&timefrom=" + timefrom + "&timeto=" + timeto;    //下面开始从获得的xml文件中读取各个字段属性
 GDownloadUrl(url, function(data) {
          var xml = GXml.parse(data);
          var point = xml.documentElement.getElementsByTagName("point");
          for (var i = 0; i < point.length; i++) {                 
            var lat=parseFloat(point[i].getAttribute("latitude"));
            var lng=parseFloat(point[i].getAttribute("longitude"));
            var polyline = new GPolyline([
             new GLatLng(lat,lng),new GLatLng(lat+0.00005,lng+0.00005)
], "#FF0000",10);
       map.addOverlay(polyline);
     }
      });       
 }
}function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
         map.setCenter(new GLatLng(30.275367,120.134317), 13);
         map.setUIToDefault();
      }
    }
    //]]>
  </script>
 
</head>
 
<body onload="load()" onunload="GUnload()">
 <p>taxi id: 
    <input type="text" id="taxiid"/>
</p>
 <p>speed range : 
     low: 
     <input type="text" id="speedlow"/>
   high: 
   <input type="text" id="speedlow"/>
</p>
 <p>
    date from: 
    <input type="text" id="datefrom"/>
   date to: 
   <input type="text" id="dateto"/>
   time from: 
   <input type="text" id="timefrom"/>
  time to: 
   <input type="text" id="timeto"/>
    
    <input type="button" onclick="draw()" value="draw point"/>
    <input type="button" onclick="draw()" value="draw trace"/>
    <br/>    
    <br/>  </p>
 <div id="map" style="width:800px; height: 480px"></div>
</body>
</html>
<?php   
 // Gets data from URL parameters
$taxiid = $_GET['taxiid'];
$speedlow = $_GET['speedlow'];
$speedhigh = $_GET['speedhigh'];
$datefrom = $_GET['datefrom'];
$dateto = $_GET['dateto'];
$timefrom = $_GET['timefrom'];
$timeto = $_GET['timeto'];
$url=" ";
if(taxiid!=" ")
$url.="id = ".$taxiid."and ";
if(speedlow!=" ")
$url.="speed > ".$speedlow+"and ";
if(speedhigh!=" ")
$url.="speed < ".$speedhigh+"and ";
if(datefrom!=" ")
$url.="date > ".$datefrom+"and ";
if(dateto!=" ")
$url.="date < ".$dateto+"and ";
if(timefrom!=" ")
$url.="time > ".$timefrom+"and ";
if(timeto!=" ")
$url.="time < ".$timeto+"and ";
    $url.=" 1";    
// Start XML file, create parent node 
 
$dom = new DOMDocument("1.0"); 
$node = $dom->createElement("point"); 
$parnode = $dom->appendChild($node);  
 
// Opens a connection to a MySQL server 
 
$connection=mysql_connect ("127.0.0.1","root","1"); 
if (!$connection) {  die('Not connected : ' . mysql_error());}  
 
// Set the active MySQL database 
 
$db_selected = mysql_select_db(taxi, $connection); 
if (!$db_selected) { 
  die ('Can\'t use db : ' . mysql_error()); 
}  
 
// Select all the rows in the ers table 
$query = "SELECT * FROM point WHERE  "; 
$query.=$url;
$result = mysql_query($query); 
if (!$result) {   
  die('Invalid query: ' . mysql_error()); 
}  
 
header("Content-type: text/xml");  
 
// Iterate through the rows, adding XML nodes for each 
 
while ($row = @mysql_fetch_assoc($result)){   
  // ADD TO XML DOCUMENT NODE   
  $node = $dom->createElement("point");   
  $newnode = $parnode->appendChild($node);    
  $newnode->setAttribute("id",$row['id']); 
  $newnode->setAttribute("longitude", $row['longitude']);   
  $newnode->setAttribute("latitude", $row['latitude']);   
  $newnode->setAttribute("speed", $row['speed']);   
  $newnode->setAttribute("isfull", $row['isfull']); 
$newnode->setAttribute("date", $row['date']);   
  $newnode->setAttribute("time", $row['time']); 
}  
 
echo $dom->saveXML(); 
 
?>

解决方案 »

  1.   

    你用浏览器调试就可以了
    chrome和Firefox都挺好的
      

  2.   

    能不能说详细点?我用浏览器可以打开html文件,但那个php文件相当于一个中间过程,怎么看啊?
      

  3.   

    用print 在IE中输出信息调试
      

  4.   

    GDownloadUrl(url, function(data) {
    alert(data);//这里看看你输出的xml是否正确
    .........});主要从JS上来调试
      

  5.   

    估计你alert会出来一个PHP的错误信息,你这段代码大大的有问题:
    改成:$url="where 1";
    if(taxiid!=" ")
    $url.=" and `id` = '".$taxiid."'";
    if(speedlow!=" ")
    $url.=" and `speed` > '".$speedlow."'";
    if(speedhigh!=" ")
    $url.=" and `speed` < '".$speedhigh."'";
    if(datefrom!=" ")
    $url.=" and `date` > '".$datefrom."'";
    if(dateto!=" ")
    $url.=" and `date` < '".$dateto."'";
    if(timefrom!=" ")
    $url.=" and `time` > '".$timefrom."'";
    if(timeto!=" ")
    $url.=" and `time` < '".$timeto."'";
    ........$query = "SELECT * FROM `point` ".$url;  
      

  6.   

    谢谢六楼。如果我在php里写上现成的sql语句,是可以生成正确的xml得到正确的结果的。应该还是条件方面有问题,但我在php里加一句 print $taxiid; 也没见页面上有什么结果啊,怎么知道php里的过程对不对呢
      

  7.   

    还有我加了alert后貌似没有报错但也没有输出任何东西
      

  8.   

    每个文件单独调试!
    对于php文件:传入正确的参数,检查结果是否正确。传入错误的参数,检查结果是否错误。要注意边界条件
      

  9.   

    就是每个文件单独调试,多用print和echo输出结果和变量~~我没做过太大的程序,不过基本好多文件的我这样也还不慢~
      

  10.   


    // Gets data from URL parameters
    $taxiid = $_GET['taxiid'];
    $speedlow = $_GET['speedlow'];
    $speedhigh = $_GET['speedhigh'];
    $datefrom = $_GET['datefrom'];
    $dateto = $_GET['dateto'];
    $timefrom = $_GET['timefrom'];
    $timeto = $_GET['timeto'];
    $where=" where 1 ";
    $taxiid && $where.=" and `id` = '$taxiid'";
    $speedlow && $where.=" and `speed` >= '$speedlow'";
    $speedhigh && $where.=" and `speed` <= '$speedhigh'";
    $datefrom && $where.=" and `date` >= '$datefrom'";
    $dateto && $where.=" and `date` <= '$dateto'";
    $timefrom && $where.=" and `time` >= '$timefrom'";
    $timeto && $where.=" and `time` <= '$timeto'";$connection=@mysql_connect ("127.0.0.1","root","1");  
    if (!$connection)die('0' . mysql_error());
    $db_selected = @mysql_select_db($taxi, $connection); //这里的$taxi这个数据库名在哪里???
    if (!$db_selected)die ('0' . mysql_error());  
    $query = "SELECT * FROM `point` ".$where;  
    $result = @mysql_query($query);  
    if (!$result) {   
      die('0' . mysql_error());  
    }
    header("Content-type: text/xml"); $dom = new DOMDocument("1.0");  
    $node = $dom->createElement("point");  
    $parnode = $dom->appendChild($node);    
    //不知道你xml的结构是怎么样的?????
    while ($row = @mysql_fetch_array($result)){
      // ADD TO XML DOCUMENT NODE   
      $node = $dom->createElement("point");
      $newnode = $parnode->appendChild($node);   
      $newnode->setAttribute("id",$row['id']);  
      $newnode->setAttribute("longitude", $row['longitude']);   
      $newnode->setAttribute("latitude", $row['latitude']);   
      $newnode->setAttribute("speed", $row['speed']);   
      $newnode->setAttribute("isfull", $row['isfull']);  
    $newnode->setAttribute("date", $row['date']);   
      $newnode->setAttribute("time", $row['time']);  
    }   
     
    echo $dom->saveXML();  
      

  11.   


    GDownloadUrl(url, function(data) {
    if(data.substr(0,1)=="<"){
    var xml = GXml.parse(data);
    var point = xml.documentElement.getElementsByTagName("point");
    for (var i = 0; i < point.length; i++) {   
    var lat=parseFloat(point[i].getAttribute("latitude"));
    var lng=parseFloat(point[i].getAttribute("longitude"));
    var polyline = new GPolyline([
    new GLatLng(lat,lng),new GLatLng(lat+0.00005,lng+0.00005)
    ], "#FF0000",10);
    map.addOverlay(polyline);
    }
    }else{
    alert("Error:\r\n"+data);
    }
    });
      

  12.   

    比如我现在想得到php文件中的$query这个变量打印出来看是否正确,应该怎么办?
      

  13.   

    .............
    $query = "SELECT * FROM `point` ".$where;  
    die($query);
    .............在JS里就会弹出来