2013-03-23 96 views
0

我害怕通讀大量教程並徹底查看相關文檔。KML數據未在地圖上顯示?

我在我的網站上使用諾基亞地圖,並動態生成一個包含與個人用戶有關的位置數據的kml文件。

KML文件生成並保存成功。

但是,數據不會顯示在地圖上(不會出現錯誤)。

這是查詢數據庫並生成KML的文件。

<?php 


session_start(); 
if(isset($_SESSION['login'])){ 

$userID = ($_SESSION['login']); 

header("Content-type: application/vnd.google-earth.kml+xml"); 
header("Content-disposition: inline; filename=$userID.kml"); 
$con=mysql_connect("****", "****", "****"); 

mysql_select_db("****"); 

if ($userID!=null){ 

$sql1="SELECT * FROM user WHERE userID='$userID'"; 

$result1 = mysql_query($sql1, $con); 
} 
    if (!$result1){ 
     die ('Invalid Query: ' . mysql_error()); 
    } 

$devIDrow = mysql_fetch_assoc($result1); 
$devIDquery = $devIDrow['uuid']; 
$name = $devIDrow['name']; 

$sql2="SELECT * FROM gps WHERE devID='$devIDquery'"; 

$result2 = mysql_query($sql2, $con); 

    if (!$result2) 
     { 
      die ('Invalid Query: ' . mysql_error()); 
     } 



$dom = new DOMDocument('1.0', 'UTF-8'); 
$dom->formatOutput = true; 
// Iterate through the rows, adding KML nodes for each 
// Creates the root KML element and appends it to the root document. 
$node = $dom->createElementNS('http://www.opengis.net/kml/2.2', 'kml'); 
$parNode = $dom->appendChild($node); 

// Creates a KML Document element and append it to the KML element. 
$dnode = $dom->createElement('Document'); 
$docNode = $parNode->appendChild($dnode); 

while ($row = mysql_fetch_assoc($result2)){ 
    $dnode = $dom->createElement("Placemark"); 
    $newnode = $docNode->appendChild($dnode); 


    $newnode = $dom->createElement("displayName"); 
    $newnode->nodeValue = $name; 
    $dnode->appendChild($newnode); 

    $newnode = $dom->createElement("Description"); 
    $newnode->nodeValue = $row['logTime']; 
    $dnode->appendChild($newnode); 

    //Coordinates are a child node of the 'Point' node  
    $pointnode = $dom->createElement("Point"); 
    $dnode->appendChild($pointnode); 

    $coordsnode = $dom->createElement("Coordinates"); 
    $coordsnode->nodeValue = $row['latitude'].",".$row['longitude']; 
    $pointnode->appendChild($coordsnode); 
} 
} 

$filename = $userID.".kml"; 
$dom->save($filename); 





mysql_close($con2); 
header("location:mapsNokia.php"); 


?> 

以下是加載了地圖

<?php 
session_start(); 
$userID = $_SESSION['login']; 
header('Access-Control-Allow-Origin: *'); 

?> 

<!DOCTYPE html> 
<html xmlns ="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>3D Protect - Map</title> 
    <link rel="stylesheet" type="text/css" href="style.css" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=7" ; IE=EmulateIE9/> 
</head> 
<body> 
    <nav> 
      <ul class="fancyNav"> 
       <li id="home"><a href="http://www.3dprotectsoftware.com/index" class="homeIcon">Home</a></li> 
       <li id="login"><a href="http://www.3dprotectsoftware.com/login">Login</a></li> 
       <li id="store"><a href="http://www.store.3dprotectsoftware.co.uk/index.php?route=product/product&filter_name=nfc&product_id=50">Store</a></li> 
       <li id="about"><a href="http://www.3dprotectsoftware.com/aboutus">About Us</a></li> 
       <li id="contact"><a href="http://www.3dprotectsoftware.com/contact">Contact Us</a></li> 
      </ul> 
     </nav> 
    </ul> 

<script type="text/javascript" src="http://api.maps.nokia.com/2.2.4/jsl.js?with=all" charset="utf-8"></script> 

<div id="map" style="z-index: -1; left:25%; right: 25%; top:25%; bottom: 25%; width: 50%; height: 50%; position: absolute;"></div> 

<script type="text/javascript"> 


/*<![CDATA[*/ 
///////////////////////////////////////////////////////////////////////////////////// 
// Don't forget to set your API credentials 
// 
// Replace with your appId and token which you can obtain when you 
// register on http://api.developer.nokia.com/ 
// 
      nokia.Settings.set("", ""); 
      nokia.Settings.set("", ""); 

//   
///////////////////////////////////////////////////////////////////////////////////// 

var map = new nokia.maps.map.Display(document.getElementById("map"), 
        { components: [ new nokia.maps.map.component.Behavior(),     
         new nokia.maps.map.component.ZoomBar(),     
         new nokia.maps.map.component.Overview(),            
         new nokia.maps.map.component.TypeSelector(),      
         new nokia.maps.map.component.ScaleBar(),     
         new nokia.maps.map.component.InfoBubbles() ],        
        'zoomLevel': 15,  
        'center': [54.04541,-2.79916] 
        }); 

    var kml = new nokia.maps.kml.Manager(); 
     // We define a callback function for parsing kml file, 
     // and then push the parsing result to map display 
     var onParsed = function (kmlManager) { 
       var resultSet; 
       // KML file was successfully loaded 
       if (kmlManager.state == "finished") { 
         // KML file was successfully parsed 
         resultSet = new nokia.maps.kml.component.KMLResultSet(kmlManager.kmlDocument, map); 
         resultSet.addObserver("state", function (resultSet) { 
           if (resultSet.state == "finished") { 
             // Retrieve map objects container from KML resultSet 
             container = resultSet.container; 

             // Add the container to the map's object collection so they will be rendered onto the map. 
             map.objects.add(container); 

             // Switch the viewport of the map do show all KML map objects within the container 
             map.zoomTo(container.getBoundingBox()); 
           } 
         }); 
         resultSet.create();      
       } 
     }; 
     // Add an observer to kml manager 
     kml.addObserver("state", onParsed); 

kml.parseKML("http://www.3dprotectsoftware.com/"+'<?php $userID = $_SESSION['login']; echo $userID;?>.kml'); 

</script> 
</body> 
</html> 

我不知道爲什麼沒有被顯示的數據的頁面。

下面是一個示例KML文件

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
    <Document> 
    <Placemark> 
     <Name>Antwan</Name> 
     <Description>2013-03-18 

20:56:39</Description> 
     <Point> 
     <Coordinates>54.04541,-2.79916</Coordinates> 
     </Point> 
    </Placemark> 
    <Placemark> 
     <Name>Antwan</Name> 


<Description>2013-03-18 21:01:42</Description> 
     <Point> 
     <Coordinates>54.04541,-2.79916</Coordinates> 
     </Point> 
    </Placemark> 
</Document> 
</kml> 

任何幫助,將不勝感激

回答

0

您的KML無效(KML/XML是區分大小寫):

http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.geocodezip.com%2Fgeoxml3_test%2FSO_Nokia.kml

<Description> should be <description> 
<Name> should be <name> 
<Coordinates> should be <coordinates> 

如果我修復這些,它適用於我:

http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?filename=http://www.geocodezip.com/geoxml3_test/SO_Nokia_correctCase.kml

+0

輝煌,謝謝!簡直不敢相信它是如此簡單。謝謝! – anthonyhumphreys 2013-03-23 14:37:04

+0

嗯......當我做出這些改變時,得到的kml文件是: <?xml version =「1.0」encoding =「UTF-8」?> anthonyhumphreys 2013-03-23 15:39:46

+0

沒關係,我修改了我的登錄腳本,打破了系統:)謝謝! – anthonyhumphreys 2013-03-23 16:10:46