Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/238689-google-locator/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.