【发布时间】:2013-03-15 10:38:48
【问题描述】:
我已经使用 Google 地理编码 v3 大约 6 个月了,但它突然停止工作(我收到 610 错误)。直到最近一周左右才停止。
然后我发现了这个(见页面顶部的粉红色框!):https://developers.google.com/maps/documentation/geocoding/v2/
我已阅读所有文档,但不知道从哪里开始!
我希望这是一个小小的改变,因为我花了很长时间才走到这一步,有人可以帮忙吗?
[在此处查看完整网站][1]
更新:
require("database.php");
// Opens a connection to a MySQL server
$con = mysql_connect("localhost", $username, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("teamwork_poh", $con);
$company = get_the_title();
$address = get_field('address_line_1');
$city = get_field('town_/_city');
$post_code = get_field('post_code');
$link = get_permalink();
$type = get_field('kind_of_organisation');
$sql = sprintf("select count('x') as cnt from markers where `name` = '%s'", mysql_real_escape_string($company));
$row_dup = mysql_fetch_assoc(mysql_query($sql,$con));
if ($row_dup['cnt'] == 0) {
mysql_query("INSERT INTO markers (`name`, `address`, `lat`, `lng`, `type`, `link`) VALUES ('".$company."', '".$address.", ".$city.", ".$post_code."', '0.0', '0.0', '".$type."', '".$link."')");
}
wp_reset_query();
require("database.php");
define("MAPS_HOST", "maps.googleapis.com");
define("KEY", "(my key)");
// 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());
}
$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/json?address=";
while ($row = @mysql_fetch_assoc($result)) {
if (!($row['lat'] * 1)) {
$geocode_pending = true;
while ($geocode_pending){
$address = $row["address"];
$id = $row["id"];
$request_url = $base_url . "" . urlencode($address) ."&sensor=false";
sleep(0.1);
$json = file_get_contents($request_url);
$json_decoded = json_decode($json);
$status = $json_decoded->status;
if (strcmp($json_decoded->status, "OK") == 0) {
$geocode_pending = false;
$lat = $json_decoded->results[0]->geometry->location->lat;
$lng = $json_decoded->results[0]->geometry->location->lng;
// echo 'here';
$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);
echo $id;
if (!$update_result) {
die("Invalid query: " . mysql_error());
}
}
else {
// failure to geocode
$geocode_pending = false;
echo "Address " . $address . " failed to geocode. ";
echo "Received status " . $status . "\n";
}
// usleep($delay);
}
}
}
【问题讨论】:
-
到底是什么问题(或者更具体地说,你的问题是什么)?我去你的网站,我看到了一张地图……
-
@duncan 它不再通过地理编码绘制标记。它在 3 月 8 日根据 google 链接停止工作,但无法确定要更改哪些内容才能再次对其进行地理编码标记。
-
查看stackoverflow.com/a/15289007/2110460了解更多信息和更新指南链接
-
@Rafe 谢谢,我遇到了这个问题,但不知道我的哪里出了问题。我试过更改网址(请参阅有问题的更新),但这并不影响它,有什么想法吗?
-
暂时忘记地图生成。你检查过你的xml吗?您确定要继续使用 xml 而不是切换到 json 吗?
标签: google-maps google-maps-api-3 google-geocoding-api