Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 771 → Rev 772

/trunk/jrest/services/CoordSearch.php
9,7 → 9,7
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
* @version $Id$
*/
class CoordSearch {
class CoordSearch extends Cel {
private $adresse_service_geonames = null;
private $adresse_service_local = null;
21,11 → 21,11
parent::__construct($config);
$this->adresse_service_geonames = $config['cel_db']['url_service_geo_geonames'];
$this->adresse_service_local = $config['cel_db']['url_service_geo_local'];
$this->adresse_service_geonames = $this->config['cel_db']['url_service_geo_geonames'];
$this->adresse_service_local = $this->config['cel_db']['url_service_geo_local'];
$this->nom_service_geocoding = $config['cel_db']['nom_service_geocoding_geonames'];
$this->nom_service_reverse_geocoding = $config['cel_db']['nom_service_reverse_geocoding_geonames'];
$this->nom_service_geocoding = $this->config['cel_db']['nom_service_geocoding_geonames'];
$this->nom_service_reverse_geocoding = $this->config['cel_db']['nom_service_reverse_geocoding_geonames'];
}
 
/**
57,7 → 57,7
 
} elseif ($this->estUneRequeteGeocoding($params)) {
$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['pays']);
$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['code_pays']);
 
$header = 'Content-Type: application/json; charset=UTF-8';
$retour = json_encode($informations_coord);
123,25 → 123,25
$this->nom_service_reverse_geocoding.
"?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lon).
"&style=full") ;
$objet_retour = json_decode($infos_commune_json);
$retour = false;
if($this->estUnRetourGeonamesValide($retour)) {
$retour = array('nom' => $objet_retour->geonames[0]->name, 'code_insee' => $objet_retour->geonames[0]->AdminCode2);
if($this->estUnRetourReverseGeocodingGeonamesValide($objet_retour)) {
$retour = array('nom' => $objet_retour->geonames[0]->name, 'code_insee' => $objet_retour->geonames[0]->adminCode4);
}
return $retour;
}
private function estUnRetourGeonamesValide($retour) {
private function estUnRetourReverseGeocodingGeonamesValide($retour) {
$valide = false;
if (is_a($retour,'stdClass') && property_exists($retour,'geonames')
&& is_array($retour->geonames) && count($retour->geonames > 0)) {
$objet_resultats = $objet_retour->geonames[0];
if (property_exists($objet_resultats,'name') && property_exists($objet_resultats,'AdminCode2')) {
$objet_resultats = $retour->geonames[0];
if (property_exists($objet_resultats,'adminName4') && property_exists($objet_resultats,'adminCode2')) {
$valide = true;
}
}
161,8 → 161,33
$requete .= "&country=".urlencode($code_pays)."&maxRows=10" ;
 
$coord_json = @file_get_contents($requete);
$objet_retour = json_decode($coord_json);
$retour = false;
if($this->estUnRetourGeocodingGeonamesValide($objet_retour)) {
$retour = array('lat' => $objet_retour->postalCodes[0]->lat,
'lng' => $objet_retour->postalCodes[0]->lng,
'nom' => $objet_retour->postalCodes[0]->placeName,
'code_insee' => $objet_retour->postalCodes[0]->postalCode
);
}
 
return $coord_json;
return $retour;
}
private function estUnRetourGeocodingGeonamesValide($retour) {
$valide = false;
if (is_a($retour,'stdClass') && property_exists($retour,'postalCodes')
&& is_array($retour->postalCodes) && count($retour->postalCodes > 0)) {
$objet_resultats = $retour->postalCodes[0];
if (property_exists($objet_resultats,'lat') && property_exists($objet_resultats,'lng')) {
$valide = true;
}
}
return $valide;
}
}
?>