
Untitled
By: a guest on
May 2nd, 2012 | syntax:
PHP | size: 1.27 KB | hits: 20 | expires: Never
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY;
$geocode_pending = true;
while ($geocode_pending) {
$address = $ulica." ".$miasto." "."Poland";
$id = $row["id"];
$request_url = $base_url . "&q=" . urlencode($address);
$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];
} 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);
}
$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')");