【发布时间】:2018-01-31 17:17:55
【问题描述】:
Google 地理编码曾经为我工作,但现在不再适用。我尝试过的一切都返回错误。它甚至没有给出原因的线索。我尝试过更改 API 密钥,尝试过不同的连接方法(我更喜欢使用 simplexml_load_file)。如果我直接在浏览器窗口中输入 URL,而不是从我的网站或什至从我的本地主机输入,它确实有效。有人对下一步尝试什么或 Google 地理编码服务的替代方案有什么建议吗?
这是我一直在使用该 Json / XML 结果的一些代码。
//URL SAVE ADDRESS
date_default_timezone_set("America/Chicago");
$address = "1600 Amphitheatre Parkway, Mountain View, CA 94043";
$address = urlencode($address);
// GOOGLE URL
$url = "https://maps.googleapis.com/maps/api/geocode/xml?address=". $address ."&sensor=false&key=AIzaSyDrGe_qr4ofea8WhZFhnPGsXNQtTiQwGhw";
echo $url; //TEMP
$xml = simplexml_load_file($url) OR $ex['tblx'] = "Unable to load XML from Googleapis.";
if(empty($xml)) {
$ex['tblx'] = "Googleapis return no values.";
} elseif("" == $xml) {
$ex['tblx'] = "Geocode problem with address, revise and retry.";
} elseif("OK" != $xml->status) {
$ex['tblx'] = "Geocode: " . ("ZERO_RESULTS" == $xml->status? "Not Found": substr($xml->status,0,30));
} else{
$dvtby0 = $uca['y0'] = (double)$xml->result->geometry->location->lat; //x
$dvtbx0 = $uca['x0'] = (double)$xml->result->geometry->location->lng;
$dvtby1 = $uca['y1'] = (double)$xml->result->geometry->viewport->southwest->lat; //a
$dvtbx2 = $uca['x1'] = (double)$xml->result->geometry->viewport->southwest->lng;
$dvtbx1 = $uca['x2'] = (double)$xml->result->geometry->viewport->northeast->lng; //b
$dvtby2 = $uca['y2'] = (double)$xml->result->geometry->viewport->northeast->lat;
}//endif
if($ex) {
var_dump($ex);
}
die("did it work?");
【问题讨论】:
-
那里不需要大括号,也不会使代码或多或少具有可读性。它只是占用空间。为什么投反对票?我的问题有什么问题?这个网站是什么让它不询问和协作解决问题?
-
为什么要在一个语句周围加上大括号?为什么要占用额外的线路?只需您的更改,您就添加了 4 行代码。它加起来。在到达分号之前,我从左到右阅读没有问题。我读得很好。我一直在我的代码中这样做
标签: php google-maps geocode