Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> xml php + google maps v3, problem z generowaniem pliku xml
mglowitz
post 23.08.2012, 12:52:01
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
 
Start new topic
Odpowiedzi
mglowitz
post 23.08.2012, 13:56:29
Post #2





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

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


Zrobiłem trochę inaczej i jest ok dzięki za pomoc
  1. <?php
  2. include ("database.php");
  3. $result = mysql_query("SELECT *, ACOS( SIN( RADIANS( `lat` ) ) * SIN( RADIANS( 49 ) ) + COS( RADIANS( `lat` ) )
  4. * COS( RADIANS( 49 )) * COS( RADIANS( `lng` ) - RADIANS( 23 )) ) * 6380 AS `distance`
  5. FROM `markers` ORDER BY distance ASC LIMIT 0,20");
  6.  
  7. $doc = new DomDocument('1.0');
  8. $root = $doc->createElement('markers');
  9. $root = $doc->appendChild($root);
  10. while($row = mysql_fetch_assoc($result))
  11. {
  12. $node = $doc->createElement('marker');
  13.  
  14. $node = $root->appendChild($node);
  15. $node->setAttribute('lat', $row['lat']);
  16. $node->setAttribute('lng', $row['lng']);
  17. $node->setAttribute('symbol', $row['symbol']);
  18. $node->setAttribute('distance', $row['distance']);
  19. }
  20. $doc->save("categories.xml");
  21. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 18.06.2024 - 06:57