Jump to content

mysql & code


leest

Recommended Posts

Ok,

 

I posted a code earlier and finally got it orking, the problem now is i got a it ambitious, and found this tutorial script I have played around with it and changed a few things but when i run it, it returns a blank page.  with no information i have echo checked the databse etc and all is working perfec, but i think i am losing it when it starts the geo code part.

 

Does any body have any ideas???

 


define("MAPS_HOST", "maps.google.com");
define("KEY", "ABQIAAAAVwap6S1SY6Dy31wrLpcgMxRBjdw_Uqb4fDsWbJeQLrPjg6_7hxRMhG5Acz3cLO1a6difeC85xaXsMA");


// Select all the rows in the markers table
$query = "SELECT * FROM joborder ";
$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=xml" . "&key=" . KEY;

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

  while ($geocode_pending) {
    $state = $row["state"];
    $joborder_id = $row["joborder_id"];
    $request_url = $base_url . "&q=" . urlencode($state);
    $xml = simplexml_load_file($request_url) or die("url not loading");

    $status = $xml->Response->Status->code;
    if (strcmp($status, "200") == 0) {
      // Successful geocode
      $geocode_pending = false;
      $coordinates = $xml->Response->Placemark->Point->coordinates;
      $coordinatesSplit = split(",", $coordinates);
      // Format: Longitude, Latitude, Altitude
      $lat = $coordinatesSplit[1];
      $lng = $coordinatesSplit[0];

      $query = sprintf("UPDATE joborder " .
             " SET lat = '%s', lng = '%s' " .
             " WHERE joborder_id = '%s' LIMIT 1;",
             mysql_real_escape_string($lat),
             mysql_real_escape_string($lng),
             mysql_real_escape_string($joborder_id));
      $update_result = mysql_query($query);
  echo  $row['joborder_id'];
  
      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 " . $state . " failed to geocoded. ";
      echo "Received status " . $status . "\n";
    }
    usleep($delay);
  }
}

Link to comment
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.