I am working on Geo coding some addresses and I found an example that uses cURL to extract the json data. For some reason it keeps returning null
I have echoed the $url
and copied it into the address field of my browser and it works as intended so I know the URL is valid. Does anyone spot a mistake in my code?
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
}