1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
<?php
function get_data($url) {
// Créer une nouvelle ressource CURL
$ch = curl_init();
// Timeout
$timeout = 5;
// l'URL de la page du site à extraire :
curl_setopt($ch, CURLOPT_URL, $url);
// Le contenu du User-Agent
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
// Retour du transfert
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,true);
// Vérifier le pper certificat
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
// Le nombre maximum de redirections HTTP à suivre
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
// pour suivre toutes location
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// Le nombre de secondes à attendre lors de la tentative de connexion
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = "https://nominatim.openstreetmap.org/reverse?format=json&lat=35.6082351&lon=-0.563609&zoom=18&addressdetails=1";
$data = get_data($url);
echo $data;
// décoder le flux JSON
$obj = json_decode($data);
// accéder à l'élément approprié
echo $obj[0]->raod;
?> |
Partager