I have been playing around with Google Maps API for the past couple of days. I got up to the point where I'm stuck because of my lack of PHP skills. After running the PHP code below, the XML returned is:
<?xml version="1.0"?>
<markers/>
The link I'm using is: http://www.icliqz.com/Dev/phpsqlsearch_genxml_php.php?latitude=41.782321&longitude=-72.612031&radius=50
The code I'm playing around with is from: http://code.google.com/apis/maps/articles/phpsqlsearch.html
I'm using Dreamweaver to work on this project. If there's a good way to debug through PHP code, I'd really appreciate it. I tried googling it up, but I'm not sure what is best for a PHP newbie. I checked that the radius of the records I have in my database. They are all within 50 miles of the coordinates I'm testing with.
The PHP code is:
<?php
require("phpsqlsearch_dbinfo.php");
// Start XML file, create parent node
$doc = new DOMDocument("1.0");
$node = $doc->createElement("markers");
$parnode = $doc->appendChild($node);
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT user, latitude, longitude, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM tbl_UserLatLng HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $doc->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->set_attribute("user", $row['user']);
$newnode->set_attribute("latitude", $row['latitude']);
$newnode->set_attribute("longitude", $row['longitude']);
$newnode->set_Attribute("distance", $row['distance']);
}
echo $doc->saveXML();
?>
Thanks in advance!