I've modified the code for my purposes as (NOTE I've named my table 'places'):
Code: Select all
$db=new mysqli('localhost','root','root','IDDB');
// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
$query = sprintf("SELECT place_address, place_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 places HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
$center_lat,
$center_lng,
$center_lat,
$radius);
$result = $db->query($query);
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
for ($i=0;$i<$result->num_rows;$i++){
$row=$result->fetch_assoc();
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['place_name']);
$newnode->setAttribute("address", $row['place_address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML();
Any suggestions/advice would be greatly appreciated.