http://www.pesttrackers.com/func.inc.php

I have a map that is connected to my db and I have a file that
geocodes the address in my db. It does not do this automatically
though. How do I incorporate this into the script for it to auto
geocode the address and then the address will show up automatically on
the map with the info and the marker.

Where does my file that geocodes the address go? So it can be called
automatically to work. I followed the tut on geocoding the address.
Please help and advise.

Here is the script that geocodes the address if that helps any:

<?php
require("mysql_connect.php");

define("MAPS_HOST", "maps.google.com");
define("KEY", "ABQIAAAA_YVHg1YHvpalent78-
SSihTz2Lg5IvdPwr5sjTZ1lEkB4NZA5RQW5S9NAp-526dMo3JeAKa8Ca-s_g");

// Opens a connection to a MySQL server
$conn = mysql_connect($dbhost, $dbusername,$dbpass,$dbname);

        mysql_select_db($dbname);
if (! $conn)
die(mysql_error());


// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://"; . MAPS_HOST . "/maps/geo?output=csv&key=" . KEY;

// Iterate through the rows, geocoding each address
while ($row = @mysql_fetch_assoc($result)) {
  $geocode_pending = true;

  while ($geocode_pending) {
    $address = $row["address"];
    $id = $row["id"];
    $request_url = $base_url . "&q=" . urlencode($address);
    $csv = file_get_contents($request_url) or die("url not loading");

    $csvSplit = split(",", $csv);
    $status = $csvSplit[0];
    $lat = $csvSplit[2];
    $lng = $csvSplit[3];
    if (strcmp($status, "200") == 0) {
      // successful geocode
      $geocode_pending = false;
      $lat = $csvSplit[2];
      $lng = $csvSplit[3];

      $query = sprintf("UPDATE markers " .
             " SET lat = '%s', lng = '%s' " .
             " WHERE id = %s LIMIT 1;",
             mysql_real_escape_string($lat),
             mysql_real_escape_string($lng),
             mysql_real_escape_string($id));
      $update_result = mysql_query($query);
      if (!$update_result) {
        die("Invalid query: " . mysql_error());
      }
    } else if (strcmp($status, "620") == 0) {
      // sent geocodes too fast
      $delay += 100000;
    } else {
      // failure to geocode
      $geocode_pending = false;
      echo "Address " . $address . " failed to geocoded. ";
      echo "Received status " . $status . "
\n";
    }
    usleep($delay);
  }
}
?>


phpsqlsearch_genxml.php (the file that the map calls out):

<?php
require("mysql_connect.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);

// Opens a connection to a mySQL server
$conn = mysql_connect($dbhost, $dbusername,$dbpass,$dbname);

        mysql_select_db($dbname);
if (! $conn)
die(mysql_error());



// Search the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 6371 *
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",
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));
$result = mysql_query($query);

if (!$result) {
  die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $row['name']);
  $newnode->setAttribute("address", $row['address']);
  $newnode->setAttribute("message", $row['message']);
  $newnode->setAttribute("lat", $row['lat']);
  $newnode->setAttribute("lng", $row['lng']);
  $newnode->setAttribute("distance", $row['distance']);


}

echo $dom->saveXML();
?>

I apologise for the code but I want you to have everything incase you
can tell me where to put this file to auto geocode the address so it
will show up on the map with a marker and the info. Thank you so much
in advance for your help.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to