document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. define("MAPS_HOST", "maps.google.com");
  4. define("KEY", "abcdefg");
  5.  
  6. // Opens a connection to a MySQL server
  7.  
  8. $connection=mysql_connect(\'localhost\', \'root\', \'root\');
  9. if (!$connection) {  die(\'Not connected : \' . mysql_error());}
  10.  
  11. // Set the active MySQL database
  12.  
  13. $db_selected = mysql_select_db(\'omits_db\', $connection);
  14. if (!$db_selected) {
  15.   die (\'Can\\\'t use db : \' . mysql_error());
  16. }
  17.  
  18. // Select all the rows in the markers table
  19. $query = "SELECT * FROM markers";
  20. $result = mysql_query($query);
  21. if (!$result) {
  22.   die("Invalid query: " . mysql_error());
  23. }
  24.  
  25. // Initialize delay in geocode speed
  26. $delay = 0;
  27. $base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY;
  28.  
  29. // Iterate through the rows, geocoding each address
  30. while ($row = @mysql_fetch_assoc($result)) {
  31.   $geocode_pending = true;
  32.  
  33.   while ($geocode_pending) {
  34.     $address = $row["address"];
  35.     $id = $row["id"];
  36.     $request_url = $base_url . "&q=" . urlencode($address);
  37.     $xml = simplexml_load_file($request_url) or die("url not loading");
  38.  
  39.     $status = $xml->Response->Status->code;
  40.     if (strcmp($status, "200") == 0) {
  41.       // Successful geocode
  42.       $geocode_pending = false;
  43.       $coordinates = $xml->Response->Placemark->Point->coordinates;
  44.       $coordinatesSplit = split(",", $coordinates);
  45.       // Format: Longitude, Latitude, Altitude
  46.       $lat = $coordinatesSplit[1];
  47.       $lng = $coordinatesSplit[0];
  48.  
  49.       $query = sprintf("UPDATE markers " .
  50.              " SET lat = \'%s\', lng = \'%s\' " .
  51.              " WHERE id = \'%s\' LIMIT 1;",
  52.              mysql_real_escape_string($lat),
  53.              mysql_real_escape_string($lng),
  54.              mysql_real_escape_string($id));
  55.       $update_result = mysql_query($query);
  56.       if (!$update_result) {
  57.         die("Invalid query: " . mysql_error());
  58.       }
  59.     } else if (strcmp($status, "620") == 0) {
  60.       // sent geocodes too fast
  61.       $delay += 100000;
  62.     } else {
  63.       // failure to geocode
  64.       $geocode_pending = false;
  65.       echo "Address " . $address . " failed to geocoded. ";
  66.       echo "Received status " . $status . "
  67. \\n";
  68.     }
  69.     usleep($delay);
  70.   }
  71. }
  72. ?>
');