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 = "
id | lat | lng | "; foreach ($arrKeys as $key) { $strTable .= "".$key." | "; } $strTable .= "|
---|---|---|---|---|
$id | $lat | $lng | "; foreach ($arrKeys as $key) { $strTable .= (isset($data[$key])) ? "".$data[$key]." | " : ""; } $strTable .= " |