I am trying to get results from a json file fetched from openstreetmap.org. When entering the url into the browser I see the json file beeing returned inside the browser. IfI try to read the json using a php script, then nothing happens. Not if I use file_get_contents, but also not if I use curl.
function geocode($address){
// url encode the address
$address = urlencode($address);
//Url openstreetmap
$url = "https://nominatim.openstreetmap.org/?addressdetails=1&q=$address&format=json&limit=1";
// Initiate curl
$ch = curl_init();
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
return json_decode($result, true);
}
And also if I use file_get_contents, there are no results:
function geocode($address){
// url encode the address
$address = urlencode($address);
$url = "http://nominatim.openstreetmap.org/search/?format=json&addressdetails=1&q={$address}&format=json&limit=1";
// get the json response
$resp_json = file_get_contents($url);
return json_decode($resp_json, true);
}
What am I possibly doing wrong?