true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_CUSTOMREQUEST => 'GET', )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); $arrData = array(); if ($err) { return false; //"cURL Error #:" . $err; } else { $data = json_decode($response); foreach ($data as $key=>$value) { if ($key=="address") { foreach ($value as $k=>$v) { //echo $k." ".$v."
"; $arrData[$k]=$v; } } }; return $arrData; } } /** ---------------------------------------------- * function writeAddress * Write data to database * $db - database handel * $id - id of location * $data - address data of location * location - address schould be an 1:1-relation * ----------------------------------------------- */ function writeAddress($db,$id,$data) { $arrKeys = array ('parking','road','house_number','industrial','neighbourhood','hamlet','suburb','postcode','city','county','country'); $strSQL="insert into address (loc_id,parking,road,house_number,industrial,"; $strSQL.="neighbourhood,hamlet,suburb,postcode,city,county,country) values ($id"; foreach ($arrKeys as $key) { $strSQL .= (isset($data[$key])) ? ",'".$data[$key]."'" : ",''"; } $strSQL.=")"; $db->exec($strSQL); } /** * function fillAddressTable($db,$limit) * $db - database handel * $limit - only look for these count of entries because of api restriction */ function fillAddressTable($db,$limit=20) { $arrIds = array(); // Get all ids from address table and write to array $strSQL="select loc_id from address"; $result=$db->query($strSQL); while ($row=$result->fetch(PDO::FETCH_ASSOC)) { $arrIds[]=$row['loc_id']; } $counter=0; $strSQL="SELECT id,lat,lng FROM location"; $arrKeys = array ('parking','road','house_number','industrial','neighbourhood','hamlet','suburb','postcode','city','county','country'); $result=$db->query($strSQL); $strTable = ""; $strTable .= ""; foreach ($arrKeys as $key) { $strTable .= ""; } $strTable .= ""; while ($row=$result->fetch(PDO::FETCH_ASSOC)) { $id=$row['id']; if (!in_array($id,$arrIds) && $counter<$limit) { $counter++; $lat=$row['lat']; $lng=$row['lng']; $data=getAddress($lat,$lng); $strTable .= ""; foreach ($arrKeys as $key) { $strTable .= (isset($data[$key])) ? "" : ""; } $strTable .= ""; sleep(1); //api restriction writeAddress($db,$id,$data); } } $strTable .= "
idlatlng".$key."
$id$lat$lng".$data[$key]."
"; return ($counter>0) ? $strTable : "Keine neuen Adressdaten."; } function cleanAddresses($db){ $strSQL="DELETE FROM address WHERE parking='' and road='' and house_number='' and industrial='' and neighbourhood='' and hamlet='' and suburb='' and postcode='' and city='' and county=''"; $db->query($strSQL); } // echo fillAddressTable($db,10);