Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> xml php + google maps v3, problem z generowaniem pliku xml
mglowitz
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 23.08.2012

Ostrzeżenie: (0%)
-----


Witam
Jestem nowy na forum więc chciałbym gorąco wszystkich pozdrowić. Chciałbym stworzyć mapę na swojej stronie taką jak https://developers.google.com/maps/articles/phpsqlsearch_v3
Po utworzeniu bazy danych z odpowiednimi kolumnami i danymi niestety przy tworzeniu pliku xml dostaję komunikat
This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.

plik php wygląda tak
<?php
header("Content-type: text/xml");
include ("database.php");

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];



// Select all the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));

$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

// Start XML file, echo parent node
echo "<markers>\n";
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'distance="' . $row['distance'] . '" ';
echo "/>\n";
}

// End XML file
echo "</markers>\n";

?>
Szukałem na google rozwiązania jednak te proponowane niestety nie zdawały egzaminu. Czy ktoś mógłby pomóc? Dodam że korzystam z PHP5
Pozdrawiam

Witam z błędem generowania pliku już sobie poradziłem wstawiłem echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n"; ale niestety pojawił się inny problem. Niestety po wstawieniu poniższego kodu nie wyświetla mi nic ani błędu ani danych. Podejrzewam że klamra zamykająca z linii 53 jest nie w tym miejscu (otwierająca w 15) ale nie jestem pewien. Kod aktualny
<?php
echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n";
include ("database.php");

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

if (isset($center_lat) && isset($center_lng) && isset($radius)){
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];



// Select all the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');

$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

// Start XML file, echo parent node
echo "<markers>\n";
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'distance="' . $row['distance'] . '" ';
echo "/>\n";
}

// End XML file
echo "</markers>\n";
}
?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.12.2025 - 19:43