126 lines
4.6 KiB
PHP
126 lines
4.6 KiB
PHP
<?php
|
|
require_once ('common/curl.php');
|
|
|
|
Class geoLocalisationLib
|
|
{
|
|
public $googleKey;
|
|
public $googleUrl = 'http://maps.google.com/maps/geo?q=';
|
|
|
|
public function __construct($listeEtablissement, &$valeur)
|
|
{
|
|
$valeur = self::createListeOfAdress($listeEtablissement);
|
|
}
|
|
|
|
public function getGoogleKey($domaineName)
|
|
{
|
|
switch ($domaineName) {
|
|
case 'extranet.sd.dev':
|
|
return ($this->googleKey = 'ABQIAAAAuKBtUyFonYJBl1fqfc78tRTTQao-JYbZvohjws19Eq-s8HocrxTKnnmfOnWxcHe01UHRIkRkZ1f17Q');
|
|
case 'extranet.sd.lan':
|
|
return ($this->googleKey = 'ABQIAAAAuKBtUyFonYJBl1fqfc78tRSKTEtsiH12Xc5SNL4Zmo_wRXVkrxR4jPIy3GOKGzZxBEOkvOsLG2CJ3w');
|
|
case 'extranet-2.0.sd.lan':
|
|
return ($this->googleKey = 'ABQIAAAAuKBtUyFonYJBl1fqfc78tRTy4fRlC-SwcCZRiggZoieobzFAiRR6bORav5_Dl3324CqVALrh-ciGFQ');
|
|
default:
|
|
return (false);
|
|
|
|
}
|
|
return ($this->googleKey);
|
|
}
|
|
|
|
/**
|
|
* Execute une requete cURL pour recuperer les infos XML
|
|
* Traitement XML avec SimpleXml.
|
|
*
|
|
* @param marqueur bien formaté $marqueur
|
|
*/
|
|
public function getCoordinates($marqueur)
|
|
{
|
|
// Pour les appelles statics. version dev pour la clef.
|
|
(isset($this->googleKey))?$googleKey = $this->googleKey:$googleKey = 'ABQIAAAAuKBtUyFonYJBl1fqfc78tRTTQao-JYbZvohjws19Eq-s8HocrxTKnnmfOnWxcHe01UHRIkRkZ1f17Q';
|
|
(isset($this->googleUrl))?$googleUrl = $this->googleUrl:$googleUrl = 'http://maps.google.com/maps/geo?q=';
|
|
|
|
$sep = ',';
|
|
$cURL = curl_init();
|
|
$user_agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
|
|
|
|
$Url = $googleUrl . urlencode(
|
|
$marqueur['adresse'].$sep.$marqueur['cp'].
|
|
$sep.$marqueur['ville'].$sep.$marqueur['pays']).'&output=xml&key='.$googleKey;
|
|
|
|
curl_setopt($cURL, CURLOPT_URL, $Url);
|
|
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
//curl_setopt($cURL, CURLOPT_USERAGENT, $user_agent);
|
|
|
|
$data = curl_exec($cURL);
|
|
|
|
curl_close($cURL);
|
|
|
|
if (isset($data) and !empty($data)) {
|
|
$xml = new SimpleXMLElement($data);
|
|
$result = simplexml_load_string($data);
|
|
$explode = explode(',' ,$result->Response->Placemark->Point->coordinates);
|
|
if (count($explode) == 3)
|
|
$coordinates = $explode;
|
|
else
|
|
$coordinates = false;
|
|
} else
|
|
$coordinates = false;
|
|
return ($coordinates);
|
|
}
|
|
|
|
public function getImage($coordonnees)
|
|
{
|
|
$image = 'http://cbk0.google.com/cbk?output=thumbnail&w=300&h=234&ll=';
|
|
|
|
return ($image.$coordonnees[1].','.$coordonnees[0]);
|
|
}
|
|
|
|
public function supprDecimales($dec)
|
|
{
|
|
if ($dec>0 )
|
|
return floor($dec);
|
|
else
|
|
return ceil($dec);
|
|
}
|
|
|
|
public function dec2dms($dec)
|
|
{
|
|
$d = self::supprDecimales($dec);
|
|
$m = self::supprDecimales(($dec - $d) * 60);
|
|
$s = abs(round(((($dec - $d) * 60) - $m) * 60));
|
|
$m = abs($m);
|
|
return $d.'°'.$m."'".$s.'"';
|
|
}
|
|
|
|
/**en cours **/
|
|
protected function createListeOfAdress($listeEtablissement)
|
|
{
|
|
$coordonnes = array();
|
|
$i = 0;
|
|
$image = 'http://cbk0.google.com/cbk?output=thumbnail&w=150&h=69&ll=';
|
|
|
|
foreach ($listeEtablissement->result->item as $etablissement)
|
|
{
|
|
$search = array();
|
|
$search['adresse'] = str_replace(' ', '+', $etablissement->Adresse);
|
|
$search['cp'] = str_replace(' ', '+', $etablissement->CP);
|
|
$search['ville'] = str_replace(' ', '+', $etablissement->Ville);
|
|
$search['pays'] = 'France';
|
|
$valeur = self::getCoordinates($search);
|
|
if ($valeur!=false) {
|
|
$coordonnes[$i]['coordonnees'] = $valeur;
|
|
$coordonnes[$i]['title'] = $etablissement->Enseigne;
|
|
$coordonnes[$i]['content'] = 'Etablissement : '.$etablissement->Nic.'<br />'.
|
|
$etablissement->Adresse.'<br />'.
|
|
'<b>'.$etablissement->CP.' '.$etablissement->Ville.'</b><br />'.
|
|
$etablissement->Pays.'<br />'.'<img src=\''.$image.$valeur[1].','.$valeur[0].'\' />'.'<br />'.
|
|
$etablissement->NafEtab.' : '.$etablissement->NafEtabLib;
|
|
|
|
}
|
|
$i++;
|
|
}
|
|
|
|
return ($coordonnes);
|
|
}
|
|
} |