Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: PHP  |  size: 1.27 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Initialize delay in geocode speed
  2.         $delay = 0;
  3.         $base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY;
  4.        
  5.         $geocode_pending = true;
  6.        
  7.           while ($geocode_pending) {
  8.                 $address = $ulica." ".$miasto." "."Poland";
  9.                 $id = $row["id"];
  10.                 $request_url = $base_url . "&q=" . urlencode($address);
  11.                 $xml = simplexml_load_file($request_url) or die("url not loading");
  12.        
  13.                 $status = $xml->Response->Status->code;
  14.                 if (strcmp($status, "200") == 0) {
  15.                   // Successful geocode
  16.                   $geocode_pending = false;
  17.                   $coordinates = $xml->Response->Placemark->Point->coordinates;
  18.                   $coordinatesSplit = split(",", $coordinates);
  19.                   // Format: Longitude, Latitude, Altitude
  20.                   $lat = $coordinatesSplit[1];
  21.                   $lng = $coordinatesSplit[0];
  22.        
  23.                 } else if (strcmp($status, "620") == 0) {
  24.                   // sent geocodes too fast
  25.                   $delay += 100000;
  26.                 } else {
  27.                   // failure to geocode
  28.                   $geocode_pending = false;
  29.                   echo "Address " . $address . " failed to geocoded. ";
  30.                   echo "Received status " . $status . "
  31.         \n";
  32.                 }
  33.                 usleep($delay);
  34.           }
  35.          
  36.         $zapytanie = mysql_query("INSERT INTO wpis (id, nazwa, miasto, adres, telefon, cena, uwagi, lat, lng, parametr) VALUES ('', '$nazwa', '$miasto', '$ulica', '$telefon', '$cena', '$uwagi', '$lat', '$lng', '99')");