raymond_feliciano Posted June 7, 2011 Share Posted June 7, 2011 I need to add a store locator into a cutomers site. I am using the google script from http://code.google.com/apis/maps/articles/phpsqlsearch.html. When I try to get the XML output to show up on the browser I get <?xml version="1.0" ?> <markers /> This is suppose to display the the dealers name address info and phone within a certain radius, but I get an empty XML file. Here is the code. require("database.php"); // 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); // Search the rows in the dealers table $query = sprintf("SELECT firstname, address, city, state_code, zipcode, phone, 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_DEALERS." HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20", mysqli_real_escape_string($connection, $center_lat), mysqli_real_escape_string($connection, $center_lng), mysqli_real_escape_string($connection, $center_lat), mysqli_real_escape_string($connection, $radius)); //$result = mysqli_query($connection, $query); $result = mysqli_query($connection, $query); if (!$result) { die("Invalid query: " . mysqli_error($connection)); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while($row = mysqli_fetch_assoc($result)){ $node = $dom->createElement("marker"); $newnode = $parnode->appendChild($node); $newnode->setAttribute("name", $row['fisrtname']); $newnode->setAttribute("address", $row['address']); $newnode->setAttribute("city", $row['city']); $newnode->setAttribute("state", $row['state_code']); $newnode->setAttribute("zip", $row['zipcode']); $newnode->setAttribute("phone", $row['phone']); $newnode->setAttribute("lat", $row['latitude']); $newnode->setAttribute("lng", $row['longitude']); $newnode->setAttribute("distance", $row['distance']); } $xmlfile = $dom->saveXML(); echo $xmlfile; Any suggestions would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/238689-google-locator/ Share on other sites More sharing options...
Maq Posted June 7, 2011 Share Posted June 7, 2011 1) Be careful where you post, I moved this thread to PHP Coding Help. 2) In the future, please place tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/238689-google-locator/#findComment-1226568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.