2013-05-18 233 views
0

我有以下代碼存儲在'genxml.php',在谷歌地圖上生成標記。該文件是從另一個文件'mobileInterface.php'中調用的。如果我在數據庫中添加另一個標記位置,在計算機瀏覽器中一切正常,我遇到的唯一問題是從移動瀏覽器加載時,標記不會立即更新,我必須退出瀏覽器並重新加載才能更新。否則,我必須直接從URL加載'genxml.php',下載內容,然後再次加載'mobileInterface.php'。谷歌地圖xml標記

我試過不緩存頁面內容,但仍然有這個問題。請有任何想法嗎?

//genxml.php

$query = "SELECT * ,DATE_FORMAT(ts, '%d-%m-%Y : %H.%i.%s') as tz FROM dataentry WHERE caseStatus = 1"; 
$result = mysql_query($query); 
if (!$result) { 
    die('Invalid query: ' . mysql_error()); 
} 

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


// Start XML file, echo parent node 
echo '<markers>'; 

// Iterate through the rows, printing XML nodes for each 
while ($row = @mysql_fetch_assoc($result)){ 
     // ADD TO XML DOCUMENT NODE 
    echo '<marker '; 
    echo 'id="' . parseToXML($row['id']) . '" '; 
    echo 'riskCategory="' . parseToXML($row['riskCategory']) . '" '; 
    echo 'EventAccidentSubject="' . parseToXML($row['EventAccidentSubject']) . '" '; 
    echo 'description="' . parseToXML($row['description']) . '" '; 
    echo 'peopleInvolved="' . parseToXML($row['peopleInvolved']) . '" '; 
    echo 'hazards="' . parseToXML($row['hazards']) . '" '; 
    echo 'address="' . parseToXML($row['address']) . '" '; 
    echo 'lat="' . $row['lat'] . '" '; 
    echo 'lng="' . $row['lng'] . '" '; 
    echo 'caseStatus="' . parseToXML($row['caseStatus']) . '" '; 
    echo 'ts="' . $row['tz'] . '" '; 
    echo '/>'; 
} 

// End XML file 
echo '</markers>'; 

?> 

//mobileInterface.php

var mobileInterfaceServer = "http://10.0.0.21/genxml.php";   
downloadUrl(mobileInterfaceServer, function(markers) {//replace markers with data 
      var xml = markers.responseXML;//replace markers with data 
      var markers = xml.documentElement.getElementsByTagName("marker"); 
      selectBox = document.getElementById('destination'); 
      for (var i = 0; i < markers.length; i++) { 
       var riskCategory = markers[i].getAttribute("riskCategory"); 
       var EventAccidentSubject = markers[i].getAttribute("EventAccidentSubject");   
       var address = markers[i].getAttribute("address"); 
       var point = new google.maps.LatLng(
       parseFloat(markers[i].getAttribute("lat")), 
       parseFloat(markers[i].getAttribute("lng")));      

       html = "<b>" + EventAccidentSubject + "</b> <br/>" + address; 

       displayLocation(markers[i]); 
       //displayLocation(point); 
       addOption(selectBox, markers[i].getAttribute("EventAccidentSubject"), point); 

       bindInfoWindow(marker, map, infoWindow, html); 

      } 

回答