Php t和Lng都是小写的,所以代码失败了(无论如何对我来说)。。。此外,如果您想在任何计算中使用它们,或者您会看到一个充满警告的屏幕:$a['lat']=(float)$xml->result->geometry->location->lat;//v3$a['
t和Lng都是小写的,所以代码失败了(无论如何对我来说)。。。此外,如果您想在任何计算中使用它们,或者您会看到一个充满警告的屏幕:$a['lat']=(float)$xml->result->geometry->location->lat;//v3$a['lon']=(浮动)$xml->result->geometry->location->lng;//v3Php t和Lng都是小写的,所以代码失败了(无论如何对我来说)。。。此外,如果您想在任何计算中使用它们,或者您会看到一个充满警告的屏幕:$a['lat']=(float)$xml->result->geometry->location->lat;//v3$a[',php,mysql,geocoding,Php,Mysql,Geocoding,t和Lng都是小写的,所以代码失败了(无论如何对我来说)。。。此外,如果您想在任何计算中使用它们,或者您会看到一个充满警告的屏幕:$a['lat']=(float)$xml->result->geometry->location->lat;//v3$a['lon']=(浮动)$xml->result->geometry->location->lng;//v3 // Change the maps host, and keys are no longer used: //define("MAPS_
// Change the maps host, and keys are no longer used:
//define("MAPS_HOST", "maps.google.com"); V2 Geocode
//define("KEY", "abcdefg"); V2 Geocode
define("MAPS_HOST", "maps.googleapis.com"); // V3 Geocode
// Change the base URL:
//$base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY V2 Geocode
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?"; //V3 Geocode
// Change the request URL:
// $request_url = $base_url . "&q=" . urlencode($address); V2 Geocode
$request_url = $base_url . "address=" . urlencode($address) . "&sensor=false"; V3 Geocode
<?php
require("../../DatabaseCredentials.php");
define("MAPS_HOST", "maps.googleapis.com");
// Opens a connection to a MySQL server
$connection = mysql_connect(localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die("Can\'t use db : " . mysql_error());
}
// Select certain fields in the Houses table
$query = "
SELECT `Active`, `SaleTypeID`, `HouseID`, `Active`, `StreetNumber`, `StreetCardinal`, `StreetName`, `City`, `State`, `ZipCode`, `Latitude`, `Longitude`
FROM `Houses`
WHERE `HouseID` = 1519 OR `HouseID` = 1520 OR `HouseID` = 1525 OR `HouseID` = 1526
";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?";
// Iterate through the rows, geocoding each address
while ($row = @mysql_fetch_assoc($result)) {
$geocode_pending = true;
while ($geocode_pending) {
$address = $row["StreetNumber"]." ".$row["StreetCardinal"]." ".$row["StreetName"].", ".$row["City"].", ".$row["State"]." ".$row["ZipCode"];
$id = $row["HouseID"];
$request_url = $base_url . "address=" . urlencode($address) . "&sensor=false";
$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);
$Latitude = $coordinatesSplit[0];
$Longitude = $coordinatesSplit[1];
$query = sprintf("UPDATE brents8_houses " .
" SET Latitude = '%s', Longitude = '%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 "This Address " . $address . " failed to geocoded again. ";
echo "Received status " . $status . "
\n";
}
usleep($delay);
}
}
?>
<?php
require("phpsqlajax_dbinfo.php");
// THE HOST HAS CHANGED, AND A KEY IS NO LONGER REQUIRED.
// v2 define("MAPS_HOST", "maps.google.com");
// v2 define("KEY", "abcdefg");
define("MAPS_HOST", "maps.googleapis.com"); // V3
// Opens a connection to a MySQL server
$connection = mysql_connect(localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die("Can\'t use db : " . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers2 WHERE 1";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Initialize delay in geocode speed
$delay = 0;
// THE BASE URL HAS CHANGED
// v2 $base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY;
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?"; // V3
// 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"];
// THE REQUEST URL HAS CHANGED
// v2 $request_url = $base_url . "&q=" . urlencode($address);
$request_url = $base_url . "address=" . urlencode($address) . "&sensor=false"; // v3
$xml = simplexml_load_file($request_url) or die("url not loading");
// THE STATUS CHECK HAS CHANGED
// v2 $status = $xml->Response->Status->code;
// v2 if (strcmp($status, "200") == 0) {
$status = $xml->status; // v3
if (strcmp($status, "OK") == 0) { // v3
// successful geocode
$geocode_pending = false;
// $coordinates = $xml->Response->Placemark->Point->coordinates;
// THE COORDINATS SPLIT HAS CHANGED
// v2 $coordinatesSplit = split(",", $coordinates);
// v2 $lat = $coordinatesSplit[0];
// v2 $lng = $coordinatesSplit[1];
$lat = $xml->result->geometry->location->lat; // v3
$lng = $xml->result->geometry->location->lng; // v3
$query = sprintf("UPDATE markers2 " .
" 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);
}
}
?>