-1
$url = "https://maps.google.com/maps/api/geocode/json?address=".urlencode($address)."&sensor=false";
$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);
echo "<pre>"; print_r($response_a);

i am using this code to receive data but all i get is ZERO_RESULTS. but the thing is, the url works when i use it in the browser, it just doesnt work with curl. any ideas?

here is a url that works in browser but does not work with curl:

https://maps.google.com/maps/api/geocode/json?address=Wiener+Stra%C3%83%C5%B8e+86+3830+Waidhofen+an+der+Thaya&sensor=false

Janus
  • 41
  • 3
  • ok i have found one error within the curl....tho i dont know why it works in browser. i have removed street numbers and postal code, this way most of it works. not the best and most accurate solution but atleast something – Janus Oct 23 '16 at 20:46
  • Are you including a key? Are you URL encoding the URL? – geocodezip Oct 24 '16 at 04:34
  • yes i do include a key and yes i do encode the url with urlencode($address) as seen in the example code – Janus Oct 24 '16 at 09:48

1 Answers1

0

It looks like something is wrong with encoding of 'Straße'.

In your sample code you have 'Stra%C3%83%C5%B8e'. Let's use this utility http://meyerweb.com/eric/tools/dencoder/ end decode this value.

You will get 'Straße'. Now let's encode 'Straße' with this utility and we will get 'Stra%C3%9Fe'.

So at this point it looks like you should have this query issued by your PHP code

https://maps.google.com/maps/api/geocode/json?address=Wiener+Stra%C3%9Fe+86+3830+Waidhofen+an+der+Thaya&key=YOUR_API_KEY

I removed sensor parameter as it's not required anymore.

xomena
  • 31,125
  • 6
  • 88
  • 117