I am making a php curl request but as the title says it returns zero results while in browser it gives results, other zipcodes gives result in curl and also in browser. (I took out the api key so it's able to test here, but same result with api key so I dont get You have exceeded your daily request but just empty array ).
Try url below in browser and curl call in https://onlinecurl.com/
https://maps.googleapis.com/maps/api/geocode/json?address=4735CC,,&componentRestrictions=country:NL&sensor=false
full code:
gives result browser but not in curl
//https://maps.googleapis.com/maps/api/geocode/json?address=4735CC,,&componentRestrictions=country:NL&sensor=false
gives result in curl & browser
//https://maps.googleapis.com/maps/api/geocode/json?address=4751AJ,,&componentRestrictions=country:NL&sensor=false
function getCoordinates($address, $zipcode, $city) {
$location = urlencode($address).','.urlencode($zipcode).','.urlencode($city);
$details_url = "https://maps.googleapis.com/maps/api/geocode/json?address=".$location;
usleep(500000);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPGET,true);
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
var_dump($response);
// gives {
"results" : [],
"status" : "ZERO_RESULTS"
}
I think problem is with your input! Try this code, if you set only address / zipcode / city then it will works. May be Google maps not able to find combination of your input address + zipcode + city.
function getCoordinates($address, $zipcode = null, $city = null ) {
// $location = urlencode($address).','.urlencode($zipcode).','.urlencode($city);
$location = urlencode($address);
$details_url = "https://maps.googleapis.com/maps/api/geocode/json?key=key&address=".$location;
usleep(500000);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPGET,true);
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
var_dump($response); }