0
直到最近,我一直在使用谷歌地理編碼來提供座標以保存在數據庫中。但是,當我最近試圖做到這一點時,失敗了,錯誤610.我仍然在使用V2,我知道這是逐步淘汰。所以,我來到這個網站,看看這個主題:Changing from Google maps api v2 to v3。我更新了我的行代碼以下的(這是我從反饋瞭解工作)從這個線程:Google geocoder v2和v3
這些是不斷變化的地理編碼
define("MAPS_HOST", "maps.googleapis.com");
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?";
$request_url = $base_url . "address=" . urlencode($address) . "&sensor=false";
地址爲V3和再次改變在返回的路徑設置xml文件經/緯
$coordinates = $xml->Response->Placemark->Point->coordinates;
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
$lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];
可與
$lat = $xml->result->geometry->location->lat;
$lng = $xml->result->geometry->location->lng;
完全取代
但仍然不適合我。當我嘗試運行它時,我不再收到錯誤610,只是「無法進行地理編碼,錯誤代碼」。
道歉我對這個東西還是比較新手的,因爲我真的去學習,所以我很感激你能給的任何幫助。這可能是我錯過的最簡單的事情。這裏是我的代碼目前:
<?php
require("phpsqlgeocode_dbinfo.php");
define("MAPS_HOST", "maps.googleapis.com");
define("KEY", *my key*);
// Opens a connection to a MySQL server
$connection = mysql_connect('*name*', $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 markers WHERE 1";
$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["address"];
$id = $row["id"];
$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;
$lat = $xml->result->geometry->location->lat;
$lng = $xml->result->geometry->location->lng;
$query = sprintf("UPDATE markers " .
" 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);
}
}
?>
非常感謝!
可能重複(http://stackoverflow.com/questions/16762433/google-geocoding-using-v3-not-showing-error) –