【发布时间】:2017-07-24 07:05:36
【问题描述】:
当我尝试在我的网站上发帖时,这就是我所得到的。我需要做什么来修复?
警告:file_get_contents(http://maps.google.com/maps/api/geocode/json?address=):打开流失败:HTTP 请求失败!第 351 行 /home/dfwwrightimc/public_html/wp-content/themes/visitdfw/functions.php 中的 HTTP/1.0 400 错误请求
function geo_lat_long($address) {
$address1 = str_replace(" ","+",$address);
$address1 = str_replace("&","%26",$address1);
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address1");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
return array('lat' => $lat, 'long' => $long);
}
【问题讨论】:
-
只是让您知道您不必将
{'results'}与 std 对象一起使用,除非它们中包含不受支持的符号(例如破折号-)。你可以去$json->results[0]->geometry->location->lat -
也许您应该使用
http://maps.googleapis.com/maps/api/geocode/中指定的documentation
标签: php wordpress google-maps google-maps-api-3