Store locator
Posted: Mon May 09, 2016 10:05 am
I am attempting to write a page that will generate hits of similar businesses within a specified radius. I found this https://developers.google.com/maps/arti ... l-with-php and it looks like what I need but it's not outputting as the example shows. Instead I get the error, "This XML file does not appear to have any style information associated with it. The document tree is shown below."
I've modified the code for my purposes as (NOTE I've named my table 'places'):
I've attached a screeengrab of my table here as well.
Any suggestions/advice would be greatly appreciated.
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.