我對地理編碼工作的一些地址,我發現,使用捲曲提取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