0

How should I configure cURL to retrieve data from the yahoo maps api?

Here is the current code

curl_setopt($ch, CURLOPT_TIMEOUT, 5000);
curl_setopt($ch, CURLOPT_URL, $geocodeurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);

Which returns a 400 - Bad request HTML file. I've checked $geocodeurl and it is a valid XML file, so I figure the problem must be the cURL options?


$geocodeurl is

 http://where.yahooapis.com/geocode?appid=** My App ID **&q=Battle%20Creek,MI&gflags=R
jisaacstone
  • 4,234
  • 2
  • 25
  • 39

2 Answers2

1

i wrote a simple class wrapper to get a basic address as a php object, which might help you get the job done! i also added a google geocoding wrapper.

to answer your question, everything is ok with the url you posted, but yes as you mentioned on your reply you should urlencode the params

$query = $this->url."?appid=".$this->appid."&flags=".$this->format;
$query .= "&location=".urlencode($address);

here is a link to my wrapper class

https://github.com/mrpollo/Geocoding-API

rroche
  • 1,262
  • 1
  • 13
  • 29
0

OK as usual I had misidentified the problem. cURL was fine, but the q= variable was not being passed through any sort of urlencode function correctly.

Worked in my browser because Firefox kindly changed the to %20. With cURL you need to be more careful. . . .

jisaacstone
  • 4,234
  • 2
  • 25
  • 39