I have a function which returns the coordinates of an address using CURL and the Google Maps API.
The code is as follows:
function get_coordinates($address_string) {
$address = urlencode($address_string);
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=" . $address . "&key=" . $api_key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
$status = $response_a->status;
return $response;
}
The code works fine for me and 99% of the web servers I use it on - but for around 1% of servers Google returns the error message:
Your client has issued a malformed or illegal request. That’s all we know.
I've checked and the Google API key is correct, PHP CURL is enabled and the PHP version matches PHP versions it is working on.
Can anyone think of any other things which could be causing Google to return this message?