我对地理编码工作的一些地址,我发现,使用卷曲提取JSON数据的example。出于某种原因,它一直返回null
我回应$url
并将其复制到我的浏览器的地址字段,它的工作原理如此我知道URL是有效的。有人在我的代码中发现错误吗?卷曲返回空值
for($count=0; $count < count($uploadedArray); $count++) {
$address = "";
$address .= $uploadedArray[$count]["Address"] . " ";
$address .= $uploadedArray[$count]["City"] . ", ";
$address .= $uploadedArray[$count]["State"] . " ";
$address .= $uploadedArray[$count]["Zip"];
$url = urlencode("https://maps.googleapis.com/maps/api/geocode/json?address=" . $address . "=%s&sensor=false");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$geoloc = json_decode(curl_exec($ch), true);
var_dump($geoloc);
echo $geoloc['results'][0]['geometry']['location']['lat']; // get lat for json
echo $geoloc['results'][0]['geometry']['location']['lng']; // get ing for json
}
PS你不需要使用卷曲只需使用'的file_get_contents($网址)',并对其进行编码如下所述。 – cmorrissey