Ma fonction geocoder ne fonctionne plus
Alors que cette fonction marchait parfaitement, elle ne fonctionne plus.
Vu que je n'ai rien modifié, est-ce du côté de Google que quelque chose a changé ?
Mon script :
Code:
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
| class geocoder{
static private $url = "http://maps.google.com/maps/api/geocode/json?key=AIzaSy***************&sensor=false&address=";
static public function getcodepostal($latlng){
$url = self::$url.urlencode($latlng);
$resp_json = self::curl_file_get_contents($url);
//$resp_json = file_get_contents($url);
$resp = json_decode($resp_json, true);
if($resp['status']='OK'){
for ($i=0; $i<count($resp['results'][0]['address_components']); $i++) {
if (in_array("postal_code", $resp['results'][0]['address_components'][$i]['types'])) return $resp['results'][0]['address_components'][$i]['long_name'];
}
}else{
return false;
}
}
static private function curl_file_get_contents($URL){
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
} |
quand j'essaye
Code:
$npa = geocoder::getcodepostal("46.206190,6.148591");
ça devrait me retourner $npa = 1201 (ou 1203)
mais ça retourne la variable vide