Я пытаюсь получить результаты из файла json, полученного с openstreetmap.org. При вводе URL-адреса в браузер я вижу, что файл json возвращается внутри браузера. Если я попытаюсь прочитать json с помощью php-скрипта, то ничего не произойдет. Нет, если я использую file_get_contents, но также и если я использую 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);
}
А также, если я использую file_get_contents, результатов нет:
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);
}
Что я, возможно, делаю неправильно?