//include_once(ROOTDIR . 'account/account.php'); /* Small portion of the code I used to call my location DB with Do note that certain functions aren't included, so you'll have to include your own. This code is used for demonstration purposes only. It doesn't include proper error-checking or the like. Don't use it to measure the distance between your space probe and Mars. Licensed under the BSD v2, (c) Alex de Landgraaf [2005] You may use this code for any purpose, just keep the above line intact. */ function normDistance($distance) { $distance = floor($distance); return $distance; } function getAfstandPostcodes($post1, $post2) { $post1 = normPostcode($post1); $post2 = normPostcode($post2); $coordarr1 = getCoordsPostcode($post1); $coordarr2 = getCoordsPostcode($post2); $dist = distance($coordarr1[0],$coordarr1[1],$coordarr2[0],$coordarr2[1]); return normDistance($dist); } function distance($lat1, $lon1, $lat2, $lon2) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; return ($miles * 1.609344); } // return string met een valide postcode voor de plaatsnaam function getPostcodePlaats($plaatsnaam) { if (strlen($plaatsnaam) > 50) { return ""; } $query = " SELECT PC_BEGIN FROM Locaties WHERE Plaats LIKE '%$plaatsnaam%'"; $result = mysql_query($query); $arr = mysql_fetch_array($result); return $arr[0] . "AA"; } // return string met plaatsnaam van postcode function getPlaatsPostcode($postcode) { // strip spaces $postcode = str_replace(" ","",$postcode); $postcode = trim($postcode); $ret = checkPostcode($postcode); if (is_string($ret)) { return $ret; } list($cijfers,$letters) = sscanf($postcode, "%4d%2s"); $query = " SELECT Plaats From Locaties WHERE PC_Begin <= '$cijfers' AND PC_Eind >= '$cijfers' AND PC_Begin != 0 AND PC_Eind != 0"; $result = mysql_query($query); $line = mysql_fetch_array($result); return $line[0]; } // return array met de 2 coordinaten, of string indien fout opgetreden function getCoordsPostcode($postcode) { $ret = checkPostcode($postcode); if (is_string($ret)) { return $ret; } list($cijfers,$letters) = sscanf($postcode, "%4d%2s"); $query = " SELECT NB, OL FROM Locaties WHERE PC_Begin <= '$cijfers' AND PC_Eind >= '$cijfers' AND PC_Begin != 0 AND PC_Eind != 0"; $coordarray = array(); $result = mysql_query($query); $line = mysql_fetch_array($result); $coordarray[0] = recalcNB($line[0]); $coordarray[1] = recalcOL($line[1]); return $coordarray; } function recalcNB($noorderbreedte) { $noorderbreedte += 182700; return recalcCoords($noorderbreedte); } function recalcOL($oosterlengte) { $oosterlengte += 10800; return recalcCoords($oosterlengte); } function recalcCoords($coord, $type = 'dec') { $graden = floor($coord / 3600); $rest = $coord % 3600; $minuten = floor($rest / 60); $seconden = $rest % 60; if ($type == 'dec') { return $graden + $minuten / 60 + $seconden / 3600; } $ret = sprintf("%02d.%02d%02d",$graden,$minuten,$seconden); return $ret; }