Get distance between two lat and lng

@param string $lat1
@param string $lng1
@param string $lat2
@param string $lng2
163781
public function getDistance($lat1, $lgn1, $lat2, $lgn2){
        $earth_radius = 6371;
        $alpha = $lat1 - $lat2;
        $beta = $lgn1 - $lgn2;
        $h = pow((sin(deg2rad($alpha/2))), 2) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * pow(sin(deg2rad($beta/2)),2);
        $dist = 2*$earth_radius*sqrt($h);

        return $dist;
    }
415267
public static double distance(Point p1, Point p2)
	{
		double x = p2.x - p1.x;
		double y = p2.y - p1.y;
		double z = p2.z - p1.z;
		return Math.sqrt(x * x + y * y + z * z);
	}
1014561
private static function sinDeltaBearing( $lat1, $lng1, $lat2, $lng2, $lat3, $lng3) {
        
        $sinLat1 = sin($lat1);
        $cosLat2 = cos($lat2);
        $cosLat3 = cos($lat3);
        $lat31 = $lat3 - $lat1;
        $lng31 = $lng3 - $lng1;
        $lat21 = $lat2 - $lat1;
        $lng21 = $lng2 - $lng1;
        $a = sin($lng31) * $cosLat3;
        $c = sin($lng21) * $cosLat2;
        $b = sin($lat31) + 2 * $sinLat1 * $cosLat3 * MathUtil::hav($lng31);
        $d = sin($lat21) + 2 * $sinLat1 * $cosLat2 * MathUtil::hav($lng21);
        $denom = ($a * $a + $b * $b) * ($c * $c + $d * $d);
        return $denom <= 0 ? 1 : ($a * $d - $b * $c) / sqrt($denom);
    }
1216497
public function distanceConditions($distance = null, $fieldName = null, $fieldLat = null, $fieldLng = null, $tableName = null) {
		if ($fieldLat === null) {
			$fieldLat = $this->_config['lat'];
		}
		if ($fieldLng === null) {
			$fieldLng = $this->_config['lng'];
		}
		if ($tableName === null) {
			$tableName = $this->_table->alias();
		}
		$conditions = [
			$tableName . '.' . $fieldLat . ' <> 0',
			$tableName . '.' . $fieldLng . ' <> 0',
		];
		$fieldName = !empty($fieldName) ? $fieldName : 'distance';
		if ($distance !== null) {
			$conditions[] = '1=1 HAVING ' . $tableName . '.' . $fieldName . ' < ' . (int)$distance;
		}
		return $conditions;
	}
1160535
public static double getDistance(double x1, double y1, double x2, double y2, int w2, int h2)
    {
        final double maxX = x2 + w2;
        final double maxY = y2 + h2;

        double min = getDistance(x1, y1, x2, y2);
        for (double x = x2; Double.compare(x, maxX) <= 0; x++)
        {
            for (double y = y2; Double.compare(y, maxY) <= 0; y++)
            {
                final double dist = getDistance(x1, y1, x, y);
                if (dist < min)
                {
                    min = dist;
                }
            }
        }
        return min;
    }
1215706
private static function tanLatGC( $lat1,  $lat2,  $lng2,  $lng3) {
        return (tan($lat1) * sin($lng2 - $lng3) + tan($lat2) * sin($lng3)) / sin($lng2);
    }
130081
function compute_string_distance( $string1, $string2 ) {
		// Vectors containing character frequency for all chars in each string
		$chars1 = count_chars($string1);
		$chars2 = count_chars($string2);

		// L1-norm of difference vector.
		$difference = array_sum( array_map( array(&$this, 'difference'), $chars1, $chars2 ) );

		// $string1 has zero length? Odd.  Give huge penalty by not dividing.
		if ( !$string1 )
			return $difference;

		// Return distance per charcter (of string1)
		return $difference / strlen($string1);
	}
574008
public function closest($date1, $date2)
    {
        return $this->diffInSeconds($date1) < $this->diffInSeconds($date2) ? $date1 : $date2;
    }
1360859
public function distance($text1, $text2)
    {
        return levenshtein($text1, $text2, $this->insertCost, $this->replaceCost, $this->deleteCost);
    }
156014
def calc_distance(lng1, lat1, lng2, lat2):
    
    ra = 6378.140  # 赤道半径 (km)
    rb = 6356.755  # 极半径 (km)
    flatten = (ra - rb) / ra  # 地球扁率
    rad_lat_1 = math.radians(lat1)
    rad_lng_1 = math.radians(lng1)
    rad_lat_2 = math.radians(lat2)
    rad_lng_2 = math.radians(lng2)
    p1 = math.atan(rb / ra * math.tan(rad_lat_1))
    p2 = math.atan(rb / ra * math.tan(rad_lat_2))
    xx = math.acos(math.sin(p1) * math.sin(p2) + math.cos(p1) * math.cos(p2) * math.cos(rad_lng_1 - rad_lng_2))
    c1 = (math.sin(xx) - xx) * (math.sin(p1) + math.sin(p2)) ** 2 / math.cos(xx / 2) ** 2
    c2 = (math.sin(xx) + xx) * (math.sin(p1) - math.sin(p2)) ** 2 / math.sin(xx / 2) ** 2
    dr = flatten / 8 * (c1 - c2)
    distance = ra * (xx + dr)
    return distance
324677
public static function calcOneOnLng($geo_lat, $scale = 'km'){
        switch(strtolower($scale)){
            case 'miles':
                $earth = 3960;
            break;

            case 'km':
            default:
                $earth = 6371;
            break;
        }
        
        //Point 1 cords
        $lat = deg2rad($geo_lat);
        $long1 = deg2rad(0);
        $long2 = deg2rad(1);
        
        //Haversine Formula
        $dlong = $long2 - $long1;
        $sinlong = sin($dlong / 2);
        
        $a = cos($lat) * cos($lat) * ($sinlong * $sinlong);
        $c = 2 * asin(min(1, sqrt($a)));
        
        return (1/($earth * $c));
    }
895579
function (letter1, letter2) {
  var index1 = scale.indexOf(letter1);
  var index2 = scale.indexOf(letter2);
  var distance = mod(index2 - index1, scale.length) + 1;

  assert(index1 > -1);
  assert(index2 > -1);
  assert(distance > 0 && distance <= scale.length);

  return distance;
}
800327
public static function distance(Vector $value1, Vector $value2) : float {
        return sqrt(self::distance2($value1, $value2));
    }
299411
public function simpleRgbDistance($color1, $color2)
    {
        $deltaR = ($color2->r - $color1->r) / 255;
        $deltaG = ($color2->g - $color1->g) / 255;
        $deltaB = ($color2->b - $color1->b) / 255;
        $deltaE = $deltaR * $deltaR + $deltaG * $deltaG + $deltaB * $deltaB;

        return ($deltaE < 0)
            ? $deltaE
            : sqrt($deltaE) * 57.73502691896258;  //  / sqrt(3) * 100;
    }
1224416
public static function reverseGeocode($lat,$lng,$limit=10)
	{
		$prefectures = array_keys(Dm_Geocoder_Prefecture::get());
		
		$addressList = array();
		
		//都道府県のCSV毎ループ
		foreach ($prefectures as $prefecture) {
			
			$location = Dm_Geocoder_Prefecture::getLocation($prefecture);
			$tolerance = 1.0;//ある程度の範囲までを対象とする
			if($location['minLat']-$tolerance > $lat) continue;
			if($location['maxLat']+$tolerance < $lat) continue;
			if($location['minLng']-$tolerance > $lng) continue;
			if($location['maxLng']+$tolerance < $lng) continue;
			
			$reader = new Dm_Geocoder_GISCSV_Reader($prefecture);
			
			// CSVの１行毎にループ
			// $rowはDm_Geocoder_Addressオブジェクト
			foreach($reader as $key => $row){
				
				$count = count($addressList);
				$distance = self::location_distance(
					$row->lat,
					$row->lng,
					$lat,
					$lng
				);
				
				if($count<$limit){
					
					$addressList[] = array(
						'address'=>$row,
						'distance'=>$distance['distance']
					);
					//１件目なら後続の処理は飛ばす
					if($count===0) continue;
					//距離順にソート
					usort($addressList, array(__CLASS__,'compareDistance'));
					
				}else{
					
					//保持している中で一番遠いaddressオブジェクト
					$end = end($addressList);
					$endDistance = $end['distance'];
					
					$nowDistance = self::location_distance($row->lat,$row->lng,$lat,$lng);
					$nowDistance = $nowDistance['distance'];
					
					if( $endDistance > $nowDistance ){
						$addressList[] = array(
							'address'=>$row,
							'distance'=>$distance['distance']
						);
						//近い順にソートする
						usort($addressList, array(__CLASS__,'compareDistance'));
						//1つ追加したので、（一番遠い）末尾から1つ削除する
						array_pop($addressList);
					}
				}
				
			}
		}
		
		foreach($addressList as $key => $row){
			$addressList[$key] = $row['address'];
		}
		
		return $addressList;
		
	}
831288
public static function havDistance($lat1, $lat2, $dLng) {
        return self::hav($lat1 - $lat2) + self::hav($dLng) * cos($lat1) * cos($lat2);
    }
174679
public function getDistance(string $name1, string $name2): float
    {
        return $this->handle->rawCommand('geodist', [$this->name, $name1, $name2]);
    }