0

恐怕要通读大量教程以及彻底搜索相关文档。

我在我的网站上使用诺基亚地图,并动态生成包含与个人用户相关的位置数据的 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>

任何帮助将不胜感激

4

1 回答 1

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

于 2013-03-23T05:33:18.647 回答