~~NOCACHE~~ class GeoCodage { public static $DEBUG = false ; public $agentEmail = 'cgiquello@openstreetmap.fr' ; public function &geoCode($address, array $countrycodes = null) { if( self::$DEBUG ) echo 'geoCode: address: '.$address.'
'; $data = array(); //$data['google'] = self::geoCode_Google($address); $data['nominatim'] = $this->geoCode_Nominatim($address, $countrycodes); return $data ; } public function &geoCode_Nominatim( $address, array $countrycodes = null){ if( self::$DEBUG ) echo 'Nominatim: address: '.$address.'
'; $url = 'http://nominatim.openstreetmap.org/search/?q=' .urlencode($address) .'&format=json'.'&email='.urlencode($this->agentEmail); if( $countrycodes != null ) $url .= '&countrycodes='.implode(',',$countrycodes); $get = file_get_contents($url); if( self::$DEBUG ) echo 'Nominatim: result: '.print_r($get,true).'
'; $results = json_decode($get); if( is_array($results) && count($results)>0 ){ $data = array( 'lat' => $results[0]->lat, 'lon' => $results[0]->lon ); } else { $data = array( 'lat' =>0, 'lon' => 0 ); } return $data; } public function &geoCode_Google($address) { if( self::$DEBUG ) echo 'Google: address: '.$address.'
'; $url = 'http://maps.google.com/maps/geo?q=' . urlencode($address) . '&output=csv&sensor=false'; $get = file_get_contents($url); if( self::$DEBUG ) echo 'Google: result: '.print_r($get,true).'
'; $records = explode(',', $get); $data = array( 'lat' => $records['2'], 'lon' => $records['3'] ); return $data; } } $dataPluginFile = DOKU_PLUGIN.'data/syntax/table.php'; if(!file_exists($dataPluginFile)){ msg('Cannot find Data plugin.', -1); } require_once $dataPluginFile; $pdt = new syntax_plugin_data_table(); $data = array( 'classes' => 'association', 'limit' => 0, 'dynfilters' => false, 'summarize' => false, 'rownumbers' => false, 'sepbyheaders' => false, 'headers' => array(), 'widths' => array(), 'filter' => array() ); $dthlp = $pdt->dthlp ; $column = $dthlp->_column('%pageid%');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('nom');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('lat');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('lon');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('adresse1');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('adresse2');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('adresse3');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('codepostal');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('ville');$data['cols'][$column['key']] = $column; $column = $dthlp->_column('web');$data['cols'][$column['key']] = $column; $sql = $pdt->_buildSQL($data); $sqlite = $dthlp->_getDB(); $res = $sqlite->query($sql); $rows = $sqlite->res2arr($res); $rowsCount = count($rows); $geocodepage = ''; if( isset($_REQUEST['geocodepage']) && strlen(trim($_REQUEST['geocodepage']))>0 ) { $geocodepage = trim($_REQUEST['geocodepage']); } echo '
geocodepage: ' .$geocodepage ; function getOsmUrl($lat,$lon) { return 'http://www.openstreetmap.org?mlat='.$lat.'&mlon='.$lon.'#map=17/'.$lat.'/'.$lon ; } foreach( $rows as $n => $row ){ list($pageid, $nom, $lat, $lon, $adr1, $adr2, $adr3, $cp, $ville, $web) = array_values($row); $addr = $adr1.', '.$adr2.', '.$adr3.','.$cp.','.$ville ; echo '

', '',$nom,' ', $addr; echo '
sur le Wiki: ',$lon,' ',$lat ,' - geocodage' ; if( $geocodepage == trim($pageid) ){ // sans le code postal (pour Nominatim) $addr = $adr1 ; $addr.= strlen(trim($adr2))>0 ? ','.$adr2 : '' ; $addr.= strlen(trim($adr3))>0 ? ','.$adr3 : '' ; $addr.= $ville ; //GeoCodage::$DEBUG = true ; $geoCod = new GeoCodage(); $geodata = $geoCod->geoCode( $addr, array('FR') ); $geo = $geodata['nominatim']; if( $geo['lon']==0 || $geo['lat'] == 0 ) $color='red'; else if( $geo['lon']!=$lon || $geo['lat']!=$lat ) $color='orange'; else $color='green'; echo '
sur le Nominatim: ',$geo['lon'],' ',$geo['lat'] ,'' ; //if( $geo['lon']==0 || $geo['lat'] == 0 ){ // $geo = $geodata['google']; // echo '
'.$geo['lat'].';'.$geo['lon']."\n"; //} } echo '

'; }