Friday, June 8, 2012

[Web] How to make xml.php for Google Map API

This code is for make xml.php file for import google map api into your homepage.

Get the keyword from user's input value(city name), and search similar city name in database.

Return filtered information into google map xml format.

$parnode = $doc->appendChild($node);

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

$sql = 'select * FROM church';
$query = "select * FROM church WHERE ch_city LIKE \"%$trimmed%\" ";

//echo $sql;

$posts = $wpdb->get_results($query);  // Run our query, getting results as an object

if (!empty($posts)) { // If the query returned something 
  foreach ($posts as $post) {   
   $address = $post->ch_street.'+'.$post->ch_city.'+'.$post->ch_state.'+'.$post->ch_zip;
   $node = $doc->createElement("marker");
   $newnode = $parnode->appendChild($node);
echo $doc->saveXML();

No comments: