本文整理汇总了PHP中distance函数的典型用法代码示例。如果您正苦于以下问题:PHP distance函数的具体用法?PHP distance怎么用?PHP distance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了distance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bearing
function bearing($lat1, $lon1, $lat2, $lon2)
{
if (round($lon1, 1) == round($lon2, 1)) {
if ($lat1 < $lat2) {
$bearing = 0;
} else {
$bearing = 180;
}
} else {
$dist = distance($lat1, $lon1, $lat2, $lon2, 'N');
$arad = acos((sin(deg2rad($lat2)) - sin(deg2rad($lat1)) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($lat1))));
$bearing = $arad * 180 / pi();
if (sin(deg2rad($lon2 - $lon1)) < 0) {
$bearing = 360 - $bearing;
}
}
$dirs = array("N", "E", "S", "W");
$rounded = round($bearing / 22.5) % 16;
if ($rounded % 4 == 0) {
$dir = $dirs[$rounded / 4];
} else {
$dir = $dirs[2 * floor((floor($rounded / 4) + 1) % 4 / 2)];
$dir .= $dirs[1 + 2 * floor($rounded / 8)];
#if ($rounded % 2 == 1)
# $dir = $dirs[round_to_int($rounded/4) % 4] . "-" . $dir;
}
$var_dist = "";
#return $dir;
if (isset($dist)) {
$var_dist = $dist . " miles";
}
return round($bearing, 0) . "º " . $dir . " " . $var_dist;
}
示例2: dpEncode
function dpEncode($points)
{
global $verySmall;
$maxDist = 0;
$absMaxDist = 0;
$dists = array();
if (count($points) > 2) {
$stack[] = array(0, count($points) - 1);
while (count($stack) > 0) {
$current = array_pop($stack);
$maxDist = 0;
for ($i = $current[0] + 1; $i < $current[1]; $i++) {
$temp = distance($points[$i], $points[$current[0]], $points[$current[1]]);
if ($temp > $maxDist) {
$maxDist = $temp;
$maxLoc = $i;
if ($maxDist > $absMaxDist) {
$absMaxDist = $maxDist;
}
}
}
if ($maxDist > $verySmall) {
$dists[$maxLoc] = $maxDist;
array_push($stack, array($current[0], $maxLoc));
array_push($stack, array($maxLoc, $current[1]));
}
}
}
$encodedPoints = createEncodings($points, $dists);
$encodedLevels = encodeLevels($points, $dists, $absMaxDist);
$encodedPointsLiteral = str_replace('\\', "\\\\", $encodedPoints);
return array($encodedPoints, $encodedLevels, $encodedPointsLiteral);
}
示例3: showlist
public function showlist()
{
global $G;
$catid = intval($_GET['catid']);
$pagesize = intval($_GET['pagesize']);
$pagesize = $pagesize > 0 ? $pagesize : 20;
$orderby = trim($_GET['orderby']);
$orderby = in_array($orderby, array('id', 'sold', 'score')) ? $orderby : 'id';
$asc = $_GET['asc'] == 1 ? 'ASC' : 'DESC';
$goodslist = $this->t('goods')->field('*,dsx_distance(' . $this->longitude . ',' . $this->latitude . ',longitude,latitude) as distance')->order("distance ASC,{$orderby} {$asc}")->page($G['page'], $pagesize)->select();
if ($goodslist) {
$newlist = array();
foreach ($goodslist as $list) {
$list['pic'] = image($list['pic']);
$list['distance'] = distance($list['distance']);
$list['dateline'] = @date('Y-m-d', $list['dateline']);
unset($list['description']);
$newlist[] = $list;
}
$goodslist = $newlist;
} else {
$goodslist = array();
}
$this->showAppData($goodslist);
}
示例4: distance
function distance($strandA, $strandB)
{
guardSameStrandLength($strandA, $strandB);
if (empty($strandA) && empty($strandB)) {
return 0;
}
return (int) areDifferent(substr($strandA, 0, 1), substr($strandB, 0, 1)) + distance(substr($strandA, 1), substr($strandB, 1));
}
示例5: filter_by_loc
function filter_by_loc($coupon_info)
{
global $search_bar_coupon_distance;
global $user_location_longitude;
global $user_location_latitude;
if (distance($user_location_latitude, $user_location_longitude, $coupon_info->latitude, $coupon_info->longitude) <= $search_bar_coupon_distance) {
return true;
}
return false;
}
示例6: intensity
function intensity()
{
$edir = getcwd();
$efile = $edir . "/event.xy";
$contents = file($efile);
$string = implode($contents);
list($qlon, $qlat, $qdep, $qmag, $ntrig, $etime, $dtime, $qstd, $r_squared, $misfit) = split('[,]', $string);
$a = -0.05;
// Distance term
$b = 1.8385;
// Magnitude term
$c = -7.8671;
// Constant
$width = (int) (log10($qmag * $qmag) * 100.0) / 100.0;
$dec = 100;
$dI = 1.0 / $dec;
$dy = (int) (log10($qmag * $qmag) * $dec) / $dec;
$lon_fact = cos($qlat * pi() / 180.0);
$lon_fact *= $lon_fact;
$dx = (int) ($dy / $lon_fact) * $dec / $dec;
$x_mn = (int) ($qlon * $dec) / $dec - $dx;
$x_mx = (int) ($qlon * $dec) / $dec + $dx;
$y_mn = (int) ($qlat * $dec) / $dec - $dy;
$y_mx = (int) ($qlat * $dec) / $dec + $dy;
$dx2 = 0.1;
$nx = (int) ($dx / $dx2 * 2) + 1;
$ny = (int) ($dy / $dx2 * 2) + 1;
$intensity_file = "intensity_map.xyz";
$fh = fopen($intensity_file, 'w');
for ($ix = 0; $ix < $nx; $ix++) {
$x = $x_mn + $dx2 * (double) $ix;
for ($iy = 0; $iy < $ny; $iy++) {
$y = $y_mn + $dx2 * (double) $iy;
$dist_xy = distance($qlon, $qlat, $x, $y);
$dist_xyz = sqrt($dist_xy * $dist_xy + $qdep * $qdep);
$pga = exp($a * $dist_xyz + $b * $qmag + $c);
fwrite($fh, "{$x} , {$y} , {$pga}, {$dist_xyz} \n");
}
}
$sfile = $edir . "/stations.xyz";
$contents = file($sfile);
foreach ($contents as $line_num => $line) {
list($slon, $slat, $smag, $hid, $tid, $sfile, $ttime, $rtime, $sig, $dis, $pgah[0], $pgaz[0], $pgah[1], $pgaz[1], $pgah[2], $pgaz[2], $pgah[3], $pgaz[3], $pgah[4], $pgaz[4]) = split('[,]', $line);
for ($j = 0; $j <= 4; $j++) {
if ($pgah[$j] > $smag) {
$smag = $pgah[$j];
}
if ($pgaz[$j] > $smag) {
$smag = $pgaz[$j];
}
}
fwrite($fh, "{$slon} , {$slat}, {$smag}\n");
}
fclose($fh);
}
示例7: distance
function distance($word1, $word2)
{
if (strlen($word1) == 0) {
return strlen($word2);
} elseif (strlen($word2) == 0) {
return strlen($word1);
} else {
$cost = $word1[0] == $word2[0] ? 0 : 1;
return min(distance(substr($word1, 1), $word2) + 1, distance($word1, substr($word2, 1)) + 1, distance(substr($word1, 1), substr($word2, 1)) + $cost);
}
}
示例8: efficiency
function efficiency($home_lat, $home_lng, $src_lat, $src_lng, $dst_lat, $dst_lng)
{
$home_lat = (double) $home_lat;
$home_lng = (double) $home_lng;
$src_lat = (double) $src_lat;
$src_lng = (double) $src_lng;
$dst_lat = (double) $dst_lat;
$dst_lng = (double) $dst_lng;
$src2dst = distance($src_lat, $src_lng, $dst_lat, $dst_lng);
$home2dst = distance($home_lat, $home_lng, $dst_lat, $dst_lng);
$home2src = distance($home_lat, $home_lng, $src_lat, $src_lng);
return ceil($src2dst / ($src2dst + $home2dst + $home2src) * 200);
}
示例9: filterStoresByDistance
function filterStoresByDistance($stores, $radius, $lat, $lng, $unit = "K")
{
//Check if Store is in the radius
foreach ($stores as $id => $store) {
$distance = distance($lat, $lng, $store['lat'], $store['long'], $unit);
$distance = intval($distance);
if ($distance <= $radius or $radius == 0) {
$stores_radius[$id] = $distance;
}
}
//Sort Radius-Store-List for Distance and rebuild stores-Array
asort($stores_radius);
foreach ($stores_radius as $id => $store) {
$stores[$id][placeholder][distance] = $store;
$stores_tmp[] = $stores[$id];
}
return $stores_tmp;
}
示例10: getAlldetails
function getAlldetails($id, $lat, $lng)
{
//! Message Loggin
comment_message_log('Start of Function : ' . __FUNCTION__);
//! Data base connection
$rConnection = dbConnection();
/*!
* Check if the database Connection is failed
*/
if (!$rConnection) {
//! Message Loggin
comment_message_log('End of Function : ' . __FUNCTION__);
return E00010;
}
//! Query
$sQuery = "SELECT * FROM `servicesubcatrelation` a,`ownerservice` b,`servicebranch` c WHERE a.sub_category_id={$id} and a.service_id=b.service_id and b.service_id=c.service_id ";
//! Executing the query
$res = mysqli_query($rConnection, $sQuery);
/*!
* Check If the Query executed properly
*/
if ($res) {
$data = array();
//! retrieve the result from the result set
while ($aRow = mysqli_fetch_assoc($res)) {
if (distance($lat, $aRow['branch_lat'], $lng, $aRow['branch_lng']) < 300) {
$data[] = $aRow;
}
}
//! Closing the connections
dbConnectionClose($rConnection);
//! Message Login
comment_message_log('Query Executed Successfully.::: ' . $sQuery);
comment_message_log('End of Function : ' . __FUNCTION__);
return $data;
} else {
comment_message_log('Query Execution failed. ::: ' . $sQuery . ' ::: ' . @mysqli_error($rConnection));
comment_message_log('End of Function : ' . __FUNCTION__);
//! Closing the connections
dbConnectionClose($rConnection);
return E00100;
}
}
示例11: showlist
public function showlist()
{
global $G;
$pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']) : 20;
$shoplist = $this->t('shop')->field('*,dsx_distance(' . $this->longitude . ',' . $this->latitude . ',longitude,latitude) as distance')->page($G['page'], $pagesize)->order('distance ASC,shopid ASC')->select();
if ($shoplist) {
$newlist = array();
foreach ($shoplist as $list) {
$list['pic'] = image($list['pic']);
$list['distance'] = distance($list['distance']);
$list['description'] = stripHtml($list['description']);
$newlist[] = $list;
}
$shoplist = $newlist;
} else {
$shoplist = array();
}
$this->showAppData($shoplist);
}
示例12: showmytask
public function showmytask()
{
global $G, $lang;
$pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']) : 20;
$tasklist = $this->t('task')->where(array('uid' => $this->uid))->page($G['page'], $pagesize)->order('tid DESC')->select();
if ($tasklist) {
$newlist = array();
foreach ($tasklist as $list) {
$list['pic'] = image($list['pic']);
$list['distance'] = distance($list['distance']);
unset($list['content']);
$newlist[] = $list;
}
$tasklist = $newlist;
} else {
$tasklist = array();
}
$this->showAppData($tasklist);
}
示例13: distToSegment
function distToSegment($firstPointSegment, $secondPointSegment, $point)
{
/* нахождение длины отрезка */
$sizeSegment = distance($firstPointSegment, $secondPointSegment);
/* нахождение проекции точки $point на отрезке по формуле t = [(p-v) . (w-v)] / |w-v|^2
* где t - $projection, p - $point, v - $firstPointSegment, w - $secondPointSegment */
$projection = (($point['X'] - $firstPointSegment['X']) * ($secondPointSegment['X'] - $firstPointSegment['X']) + ($point['Y'] - $firstPointSegment['Y']) * ($secondPointSegment['Y'] - $firstPointSegment['Y'])) / $sizeSegment;
if ($projection < 0) {
// если проекция на точке $firstPointSegment
$pointOnSegment = $firstPointSegment;
} elseif ($projection > 1) {
// если проекция на точке $secondPointSegment
$pointOnSegment = $secondPointSegment;
} else {
// если проекция не на границах отрезка
$pointOnSegment = array('X' => $firstPointSegment['X'] + $projection * ($secondPointSegment['X'] - $firstPointSegment['X']), 'Y' => $firstPointSegment['Y'] + $projection * ($secondPointSegment['Y'] - $firstPointSegment['Y']));
}
/* массив с минимальным расстоянием, и расположением точки на отрезке */
return array('DISTANCE' => sqrt(distance($point, $pointOnSegment)), 'POINT' => $pointOnSegment);
}
示例14: main
function main($lat, $lon, $offset, $date_search, $distance_tolerance)
{
$rows_per_page = 10;
$cxn = $GLOBALS['cxn'];
$sql = "SELECT * FROM user_events\n\t\t\tWHERE end_date >= '{$date_search}'\n\t\t\tORDER BY start_date ASC\n\t\t\tLIMIT {$offset}, {$rows_per_page}";
$res = mysqli_query($cxn, $sql) or die("could not pull events");
//echo $sql;
$count = mysqli_num_rows($res);
//echo "Count:".$count;
if ($count == 0) {
//user has no events!
$arr = array("status" => 0, "content" => "No events!");
echo json_encode($arr);
exit;
}
// all results will be appended to this var:
$search_output = "";
while ($row = mysqli_fetch_assoc($res)) {
//event_id user_id event_title event_description end_date start_date date_created public
extract($row);
//echo "pulling event $event_id <br />";
$query_id = "SELECT * FROM event_address WHERE event_id = '{$event_id}'";
$res2 = mysqli_query($cxn, $query_id) or die("failed to pull address");
$row_addy = mysqli_fetch_assoc($res2);
//address_id event_id address_text x_coord y_coord
extract($row_addy);
$distance = distance($x_coord, $y_coord, $lat, $lon, "m");
/* after everything is extracted:
assemble the event and make the html output
*/
if ($distance <= $distance_tolerance) {
$all_vars = array("event_id" => $event_id, "user_id" => $user_id, "event_description" => $event_description, "event_title" => $event_title, "start_date" => $start_date, "end_date" => $end_date, "venue_address" => $address_text, "lat" => $x_coord, "lon" => $y_coord, "distance" => $distance, "search_output" => $search_output, "isContactInfo" => $is_contactable, "contactInfo" => $contact_info, "contactType" => $contact_type);
$search_output = search_output_func_users($all_vars);
//see search_functions.php
}
}
$content_array = array("status" => 1, "content" => $search_output);
return $content_array;
}
示例15: lookUp
function lookUp($loc, $mask, $pdo, $SENDER_URL, $APP_INFO)
{
$user = getUser($mask, $pdo);
$list = getMatchList($mask, $pdo);
if (getUser($mask, $pdo)["friendMask"] != 'nill') {
sendReply("Your friend has left the conversation.", getFMask($mask, $pdo), $SENDER_URL, $APP_INFO);
sendReply(exitCoversation($mask, $pdo), $mask, $SENDER_URL, $APP_INFO);
}
$found = FALSE;
foreach ($list as $listUser) {
if (distance($listUser["lat"], $listUser["longi"], $user["lat"], $user["longi"], "K") <= 10) {
updateFriend($mask, $listUser["mask"], $pdo);
updateFriend($listUser["mask"], $mask, $pdo);
$user = $listUser["username"];
$found = TRUE;
break;
}
}
if ($found) {
return "You have been matched up with {$user}.\n Type FSTR M <message> and send it to 77100 to start the conversation.";
} else {
return "Sorry no match found, please try again later.";
}
}