extranet/library/Scores/classMMap.php
2011-09-13 07:08:52 +00:00

173 lines
8.4 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?
if ( !function_exists('htmlspecialchars_decode') )
{
function htmlspecialchars_decode($text)
{
return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}
}
require_once 'common/curl.php';
if ( !function_exists('supprDecimales') )
{
function supprDecimales($dec) {
if ($dec>0 )
return floor($dec);
else
return ceil($dec);
}
}
if ( !function_exists('dec2dms') )
{
function dec2dms($dec) {
$d = supprDecimales($dec);
$m = supprDecimales(($dec - $d) * 60);
$s = abs(round(((($dec - $d) * 60) - $m) * 60));
$m = abs($m);
return $d.'°'.$m."'".$s.'"';
}
}
/** Retourne la distance en kilomètres entre 2 points à la surface de la terre
** Calcul effectué avec la sphère « GRS80 » de rayon R = 6378,187 km
** Autre sphère possible : « Picard » de rayon R = 6371,598 km
**
** @param double $latA Latitude du point A en décimal
** @param double $lonA Longitude du point A en décimal
** @param double $latB Latitude du point B en décimal
** @param double $lonB Longitude du point B en décimal
** @return unknown
**/
function distance($latA=0, $lonA=0, $latB=0, $lonB=0) {
//s(AB) = arc cos (sinjA sinjB + cos jA cosjB cosdl)
// avec dl = lB - lA
$e=pi()*$latA/180;
$f=pi()*$lonA/180;
$g=pi()*$latB/180;
$h=pi()*$lonB/180;
$j=acos(cos($e)*cos($g)*cos($f)*cos($h) + cos($e)*sin($f)*cos($g)*sin($h) + sin($e)*sin($g));
return round(6371.598*$j,3); // div par 1.852 ==> résultat en miles nautiques
}
class MMap {
public $body = '';
public $header = '';
public $cookie = '';
public $codeRetour = 0;
public $codeRetour2 = 0;
public $latitudeDec= 0; // Latitude en Décimal
public $latitudeDeg= 0; // Latitude en Dégrés
public $longitudeDec= 0; // Longitude en Décimal
public $longitudeDeg= 0; // Longitude en Dégrés
public $precision = 0;
public $adresseValidee='';
function __construct($adresse, $cp, $ville, $pays='France') {
/*
$referer='http://maps.google.fr/?output=html';
$page=getUrl($referer, '', '', $referer, false, 'maps.google.fr');
$this->body=$page['body'];
$this->codeRetour=$page['code'];
$this->header=$page['header'];
$this->cookie=$this->header['Set-Cookie'];
$url='http://maps.google.fr/maps?f=q&output=html&q='.urlencode($adresse.', '.$cp.' '. $ville.', '.$pays);
$page=getUrl($url, $this->cookie, '', $referer, false, 'maps.google.fr');
$this->body=$page['body'];
$this->codeRetour=$page['code'];
$this->header=$page['header'];
if (strpos($this->body, '<p>Nous ne sommes pas parvenus à localiser l\'adresse : <br />')===true) return false;
$this->adresseValidee=strtoupper(htmlspecialchars_decode(str_replace('<br>', ', ', @getTextInHtml($this->body, '<p><table cellpadding="0" cellspacing="0" border="0"><tr><td valign="center" nowrap>', ' nowrap>', '</td>')), ENT_QUOTES));
$this->latitudeDec=@getTextInHtml($this->body, 'latitude_e6=', '=','&')/1000000;
$this->longitudeDec=@getTextInHtml($this->body, 'longitude_e6=', '=','&');
if ($this->longitudeDec>1000000000)
$this->longitudeDec=-(4294967293-$this->longitudeDec)/1000000;
else
$this->longitudeDec=$this->longitudeDec/1000000;
$this->latitudeDeg=dec2dms($this->latitudeDec);
$this->longitudeDeg=dec2dms($this->longitudeDec);
if ($this->codeRetour==200)
return true;
//$latitude_range = (180 * $range) / ($pi * $radius_of_earth);
//$longitude_range = (180 * $range) / ($pi * $radius_of_earth * sin((90 - $alat) * $pi / 180));
*/
$apiKey='ABQIAAAAuKBtUyFonYJBl1fqfc78tRQvADPcxwXf3Q2QIE-M32vuSkrxiBRLUHDB_YSLeTscTDeWRKM_wILaaw';
$url='http://maps.google.com/maps/geo?q='.urlencode($adresse.', '.$cp.' '. $ville.', '.$pays).'&output=xml&key='.$apiKey;
$referer='';//http://maps.google.fr/?output=html';
$page=getUrl($url, '', '', $referer, false, 'maps.google.com', '', 2);
$this->body=$page['body'];
$this->codeRetour=$page['code'];
$this->header=$page['header'];
//die($this->body=$page['body']);
//{"name":"3 rue viète, 75017 paris, france","Status":{"code":200,"request":"geocode"},"Placemark":[{"id":"p1","address":"3, Rue Viète, 75017 17ème Arrondissement, Paris, France","AddressDetails":{"Country":{"CountryNameCode":"FR","AdministrativeArea":{"AdministrativeAreaName":"Ile-de-France","SubAdministrativeArea":{"SubAdministrativeAreaName":"Paris","Locality":{"LocalityName":"Paris","DependentLocality":{"DependentLocalityName":"17ème Arrondissement","Thoroughfare":{"ThoroughfareName":"3, Rue Viète"},"PostalCode":{"PostalCodeNumber":"75017"}}}}}},"Accuracy": 8},"Point":{"coordinates":[2.306174,48.883705,0]}}]}
/*<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>3 rue viète, 75017 paris, france</name><Status><code>200</code><request>geocode</request></Status><Placemark id="p1"><address>3, Rue Viète, 75017 17ème Arrondissement, Paris, France</address><AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>FR</CountryNameCode><AdministrativeArea><AdministrativeAreaName>Ile-de-France</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Paris</SubAdministrativeAreaName><Locality><LocalityName>Paris</LocalityName><DependentLocality><DependentLocalityName>17ème Arrondissement</DependentLocalityName><Thoroughfare><ThoroughfareName>3, Rue Viète</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>75017</PostalCodeNumber></PostalCode></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><Point><coordinates>2.306174,48.883705,0</coordinates></Point></Placemark></Response></kml>*/
/*
0 Unknown location. (Since 2.59)
1 Country level accuracy. (Since 2.59)
2 Region (state, province, prefecture, etc.) level accuracy. (Since 2.59)
3 Sub-region (county, municipality, etc.) level accuracy. (Since 2.59)
4 Town (city, village) level accuracy. (Since 2.59)
5 Post code (zip code) level accuracy. (Since 2.59)
6 Street level accuracy. (Since 2.59)
7 Intersection level accuracy. (Since 2.59)
8 Address level accuracy. (Since 2.59)
*/
$this->precision=@getTextInHtml($this->body, '<AddressDetails Accuracy', '="', ' ');
$this->adresseValidee=strtoupper(@getTextInHtml($this->body, '<address>', 'adress>', '</address>'));
$strTmp=@getTextInHtml($this->body, '<Point><coordinates>', '<coordinates>', '</coordinates>');
$tabTmp=explode(',', $strTmp);
if (isset($tabTmp[1]) == false) {
return false;
}
$this->latitudeDec = $tabTmp[1];
$this->longitudeDec = $tabTmp[0];
$this->latitudeDeg = dec2dms($this->latitudeDec);
$this->longitudeDeg = dec2dms($this->longitudeDec);
/*
200 G_GEO_SUCCESS No errors occurred; the address was successfully parsed and its geocode has been returned.
400 G_GEO_BAD_REQUEST A directions request could not be successfully parsed.
500 G_GEO_SERVER_ERROR A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.
601 G_GEO_MISSING_QUERY The HTTP q parameter was either missing or had no value. For geocoding requests, this means that an empty address was
specified as input. For directions requests, this means that no query was specified in the input.
602 G_GEO_UNKNOWN_ADDRESS No corresponding geographic location could be found for the specified address. This may be due to the fact that the address
is relatively new, or it may be incorrect.
603 G_GEO_UNAVAILABLE_ADDRESS The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual
reasons.
604 G_GEO_UNKNOWN_DIRECTIONS The GDirections object could not compute directions between the points mentioned in the query. This is usually because
there is no route available between the two points, or because we do not have data for routing in that region.
610 G_GEO_BAD_KEY The given key is either invalid or does not match the domain for which it was given.
620 G_GEO_TOO_MANY_QUERIES The given key has gone over the requests limit in the 24 hour period.
*/
if ($this->codeRetour2==200)
return true;
return false;
}
/* if (latnorth == 'S') latdir='-'
if (lonwest == 'W') longdir='-'
latdec=Math.round(lat1)+lat2/60
londec=Math.round(long1)+long2/60
gmdatalat=latdir+latdec.toFixed(6)
gmdatalon=longdir+londec.toFixed(6)
//GM_log( 'Latdec:'+gmdatalat+' LongDec:'+gmdatalon)
gmx=gmdatalat*Math.pow(10,6)
gmy=gmdatalon*Math.pow(10,6)
if (gmx < 0) gmx=gmx+Math.pow(2,32)*/
}
?>