Advertisement
Guest User

Untitled

a guest
Feb 4th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. // Get parameters from URL
  2. $center_lat = $_GET["lat"];
  3. $center_lng = $_GET["lng"];
  4. $radius = $_GET["radius"];
  5.  
  6. // Start XML file, create parent node
  7. $dom = new DOMDocument("1.0");
  8. $node = $dom->createElement("markers");
  9. $parnode = $dom->appendChild($node);
  10.  
  11. // Opens a connection to a mySQL server
  12. $connection=mysql_connect (localhost, $username, $password);
  13. if (!$connection) {
  14. die("Not connected : " . mysql_error());
  15. }
  16.  
  17. // Set the active mySQL database
  18. $db_selected = mysql_select_db($database, $connection);
  19. if (!$db_selected) {
  20. die ("Can\'t use db : " . mysql_error());
  21. }
  22.  
  23.  
  24.  
  25.  
  26. // Search the rows in the markers table
  27. $query = sprintf("SELECT address, 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 markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
  28. mysql_real_escape_string($center_lat),
  29. mysql_real_escape_string($center_lng),
  30. mysql_real_escape_string($center_lat),
  31. mysql_real_escape_string($radius));
  32. $result = mysql_query($query);
  33.  
  34.  
  35.  
  36. $result = mysql_query($query);
  37. if (!$result) {
  38. die("Invalid query: " . mysql_error());
  39. }
  40.  
  41. header("Content-type: text/xml");
  42.  
  43. // Iterate through the rows, adding XML nodes for each
  44. while ($row = @mysql_fetch_assoc($result)){
  45. $node = $dom->createElement("marker");
  46. $newnode = $parnode->appendChild($node);
  47. $newnode->setAttribute("name", $row['name']);
  48. $newnode->setAttribute("address", $row['address']);
  49. $newnode->setAttribute("lat", $row['lat']);
  50. $newnode->setAttribute("lng", $row['lng']);
  51. $newnode->setAttribute("distance", $row['distance']);
  52. }
  53.  
  54. echo $dom->saveXML();
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement