Exact distance with Haversine formula

@param LatLng $coord

@return float
@see http://www.movable-type.co.uk/scripts/latlong.html
332090
public function exactDistanceFrom(LatLng $coord)
    {
        $lat1 = deg2rad($this->getLat());
        $lat2 = deg2rad($coord->getLat());
        $lon1 = deg2rad($this->getLng());
        $lon2 = deg2rad($coord->getLng());

        $dLatHalf = ($lat2 - $lat1) / 2;
        $dLonHalf = ($lon2 - $lon1) / 2;

        $a = pow(sin($dLatHalf), 2) + cos($lat1) * cos($lat2) * pow(sin($dLonHalf), 2);
        $c = 2 * atan2(sqrt($a), sqrt(1 - $a));

        return $c * UnitsType::EARTH_RADIUS;
    }
117779
static double havDistance(double lat1, double lat2, double dLng) {
        return hav(lat1 - lat2) + hav(dLng) * cos(lat1) * cos(lat2);
    }
1107929
public function isCoordinateOnVertex(LatLng $coord)
    {
        $paths = ArrayHelper::getValue($this->options, 'paths');
        foreach ($paths as $vertex) {
            if ($vertex->lat == $coord->lat && $vertex->lng == $coord->lng) {
                return true;
            }
        }
        return false;
    }
1366565
def coord(self, offset=(0,0)):
		''''''
		(tilex, tiley) = self.tile
		(offsetx, offsety) = offset
		world_tiles = 1<<self.zoom
		x = ( tilex + 1.0*offsetx/TILES_WIDTH ) / (world_tiles/2.) - 1
		y = ( tiley + 1.0*offsety/TILES_HEIGHT) / (world_tiles/2.) - 1
		lon = x * 180.0
		y = math.exp(-y*2*math.pi)
		e = (y-1)/(y+1)
		lat = 180.0/math.pi * math.asin(e)
		return (lat, lon)
863393
function getCoordDistance($latitude1, $longitude1, $latitude2, $longitude2)
        {
            $earth_radius = 6371;

            $latitude1 = floatval($latitude1);
            $longitude1 = floatval($longitude1);
            $latitude2 = floatval($latitude2);
            $longitude2 = floatval($longitude2);

            $dLat = deg2rad($latitude2 - $latitude1);
            $dLon = deg2rad($longitude2 - $longitude1);

            $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon / 2) * sin($dLon / 2);
            $c = 2 * asin(sqrt($a));
            $d = $earth_radius * $c;

            return $d;

        }
212939
public static Coordinate[] getFurthestCoordinate(Coordinate base, Coordinate[] coords) {
                double distanceMax = Double.MIN_VALUE;
                Coordinate farCoordinate = null;
                for (Coordinate coord : coords) {
                        double distance = coord.distance(base);
                        if (distance > distanceMax) {
                                distanceMax = distance;
                                farCoordinate = coord;
                        }
                }

                if (farCoordinate != null) {
                        return new Coordinate[]{base, farCoordinate};
                } else {
                        return null;
                }
        }
646091
public function getDistance($geo1, $geo2)
    {
        try {
            $lat1 = $geo1['lat'];
            $lng1 = $geo1['lng'];
            $lat2 = $geo2['lat'];
            $lng2 = $geo2['lng'];

            $earthRadius = 6367000; //approximate radius of earth in meters

            $lat1 = ($lat1 * pi() ) / 180;
            $lng1 = ($lng1 * pi() ) / 180;

            $lat2 = ($lat2 * pi() ) / 180;
            $lng2 = ($lng2 * pi() ) / 180;

            $calcLongitude = $lng2 - $lng1;
            $calcLatitude = $lat2 - $lat1;
            $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
            $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
            $calculatedDistance = $earthRadius * $stepTwo;

            return round($calculatedDistance);
        } catch (Exception $e) {
            throw $e;
        }
    }
552934
def haversine(self, other):
        
        # convert decimal degrees to radians
        lon1, lat1, lon2, lat2 = map(radians,\
                [self.lon.low, self['lat'].low, other.lon.low,
                    other['lat'].low])
        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2) ** 2
        c = 2 * asin(sqrt(a))
        # multiply by radius of the earth
        # km = 6367 * c
        miles = 3961 * c
        return miles
916390
public function trimPerc($coords) {
        list($x1, $y1, $x2, $y2) = $coords;
        $size = (object) $this->thumb->getCurrentDimensions();

        // Convert percentage values to what GdThumb expects
        $x = round($x1 * $size->width);
        $y = round($y1 * $size->height);
        $width = round($x2 * $size->width - $x);
        $height = round($y2 * $size->height - $y);
        $this->thumb->crop($x, $y, $width, $height);
        return $this;
    }
1034602
public function getLongitude() : ?float 
    {
        if ( ! $this->hasLongitude()) {
            $this->setLongitude($this->getDefaultLongitude());
        }
        return $this->longitude;
    }
84241
public static function WGStoCHx($lat, $long)
    {

        // Converts decimal degrees sexagesimal seconds
        $lat = self::DECtoSEX($lat);
        $long = self::DECtoSEX($long);

        // Auxiliary values (% Bern)
        $lat_aux = ($lat - 169028.66) / 10000;
        $long_aux = ($long - 26782.5) / 10000;

        // Process X
        $x = 200147.07
            + 308807.95 * $lat_aux
            + 3745.25 * pow($long_aux, 2)
            + 76.63 * pow($lat_aux, 2)
            - 194.56 * pow($long_aux, 2) * $lat_aux
            + 119.79 * pow($lat_aux, 3);

        return $x;

    }
652633
protected static function getBaseCoordinate(self $coordinate)
    {
        $latitude   = $coordinate->getLatitude()->toNative();
        $longitude  = $coordinate->getLongitude()->toNative();
        $ellipsoid  = BaseEllipsoid::createFromName($coordinate->getEllipsoid()->toNative());
        $coordinate = new BaseCoordinate(array($latitude, $longitude), $ellipsoid);

        return $coordinate;
    }
973606
def _get_coord(self, coord):
        
        x, y = coord
        return self.ctypes.c_int(y << 16 | x)
906492
public function distance(LatLng $to)
	{
		// radius in km, assuming a spherical Earth
		$er = 6366.707;

		$latFrom = deg2rad($this->lat);
		$latTo	 = deg2rad($to->lat);
		$lngFrom = deg2rad($this->lng);
		$lngTo	 = deg2rad($to->lng);

		$x1 = $er * cos($lngFrom) * sin($latFrom);
		$y1 = $er * sin($lngFrom) * sin($latFrom);
		$z1 = $er * cos($latFrom);

		$x2 = $er * cos($lngTo) * sin($latTo);
		$y2 = $er * sin($lngTo) * sin($latTo);
		$z2 = $er * cos($latTo);

		$d = acos(sin($latFrom)*sin($latTo) + cos($latFrom)*cos($latTo)*cos($lngTo-$lngFrom)) * $er;

		return $d;
	}
624586
public function exactDistanceSLCFrom(LatLng $coord, $unit = UnitsType::KILOMETERS)
    {
        $lat1 = $this->getLat();
        $lat2 = $coord->getLat();
        $lon1 = $this->getLng();
        $lon2 = $coord->getLng();

        $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;

        switch ($unit) {
            case UnitsType::KILOMETERS:
                $distance = $miles * 1.609344;
                break;
            case UnitsType::NAUTIC_MILES:
                $distance = $miles * 0.8684;
                break;
            case UnitsType::MILES:
            default:
                $distance = $miles;
        }
        return $distance;
    }
564172
def eqCoords(self, zerolat=False):
        
        lat = 0.0 if zerolat else self.lat
        return utils.eqCoords(self.lon, lat)
541197
public static function LL2Utm( string $ellipsoid, $lat, $long )
   {

      if ( ! isset( Ellipsoid::$Ellipsoid[ $ellipsoid ] ) )
      {
         // The defined ellipsoid does not exist.
         return false;
      }

      // Get the longitude decimal value
      $ln = ( ( $long instanceof AbstractElement )
         ? $long->getDecimalValue()
         : ( \is_double( $long ) ? $long : \doubleval( $long ) )
      );

      // Get the latitude decimal value
      $lt = ( ( $lat instanceof AbstractElement )
         ? $lat->getDecimalValue()
         : ( \is_double( $lat ) ? $lat : \doubleval( $lat ) )
      );

      // Init some required parameters
      $longOrigin      = null;
      $eccPrimeSquared = null;
      $longOriginRad   = null;
      $k0              = 0.9996;

      // Doing the calculation
      $a               = Ellipsoid::$Ellipsoid[ $ellipsoid ][ 0 ];
      $eccSquared      = Ellipsoid::$Ellipsoid[ $ellipsoid ][ 1 ];
      $N = null; $T = null; $C = null; $A = null; $M = null;
      $longTemp        = ( $ln + 180.0 ) - \intval( ( $ln + 180 ) / 360 ) * 360 - 180;
      $latRad          = $lt * self::DEG2RAD;
      $longRad         = $longTemp * self::DEG2RAD;
      $zoneNumber      = \intval( ( $longTemp + 180 ) / 6 ) + 1;

      if ( $lt >= 56.0 && $lt < 64.0 && $longTemp >= 3.0 && $longTemp < 12.0 )
      {
         $zoneNumber = 32;
      }

      if ( $lt >= 72.0 && $lt < 84.0 )
      {
         if ( $longTemp >= 0.0  && $longTemp <  9.0 )
         {
            $zoneNumber = 31;
         }
         else if ( $longTemp >= 9.0  && $longTemp < 22.0 )
         {
            $zoneNumber = 33;
         }
         else if ( $longTemp >= 22.0 && $longTemp < 33.0 )
         {
            $zoneNumber = 35;
         }
         else if ( $longTemp >= 33.0 && $longTemp < 42.0 )
         {
            $zoneNumber = 37;
         }
      }

      $longOrigin    = ( $zoneNumber - 1 ) * 6 - 180 + 3;
      $longOriginRad = $longOrigin * self::DEG2RAD;
      $UTMZone       = \sprintf(
         '%d%s',
         $zoneNumber,
         self::UTMLetterDesignator($lt)
      );

      $eccPrimeSquared = ( $eccSquared ) / ( 1 - $eccSquared );
      $N               = $a / \sqrt( 1 - $eccSquared * \sin( $latRad ) * \sin( $latRad ) );
      $T               = \tan( $latRad ) * \tan( $latRad );
      $C               = $eccPrimeSquared * \cos( $latRad ) * \cos( $latRad );
      $A               = \cos( $latRad ) * ( $longRad - $longOriginRad );
      $M               = $a * (
            ( 1 - $eccSquared/4 - 3 * $eccSquared * $eccSquared/64 - 5 * $eccSquared * $eccSquared * $eccSquared / 256 )
            * $latRad
            - (3 * $eccSquared/8 + 3 * $eccSquared * $eccSquared/32 + 45 * $eccSquared * $eccSquared * $eccSquared/1024)
              * \sin( 2 * $latRad )
            + ( 15 * $eccSquared * $eccSquared / 256 + 45 * $eccSquared * $eccSquared * $eccSquared / 1024 )
              * \sin( 4 * $latRad )
            - ( 35 * $eccSquared * $eccSquared * $eccSquared / 3072) * \sin( 6 * $latRad )
         );

      $UTMEasting = (double) ( $k0 * $N * ( $A + ( 1 - $T + $C ) * $A * $A * $A / 6
                                            + ( 5 - 18 * $T + $T * $T + 72 * $C - 58 * $eccPrimeSquared )
                                              * $A * $A * $A * $A * $A / 120 ) + 500000.0
      );
      $UTMEasting = \round( $UTMEasting, 0 );
      $UTMNorthing = (double) ( $k0
                                * ( $M + $N * \tan( $latRad ) * ( $A * $A / 2 + ( 5 - $T + 9 * $C + 4 * $C * $C )
                                                                                * $A * $A * $A * $A / 24 + ( 61 - 58 * $T + $T * $T + 600 * $C - 330 * $eccPrimeSquared )
                                                                                                           * $A * $A * $A * $A * $A * $A / 720 ) )
      );

      if ( $lt < 0 )
      {
         $UTMNorthing += 10000000.0;
      }

      $UTMNorthing = \round( $UTMNorthing, 0 );

      return "{$UTMZone} E {$UTMEasting} N {$UTMNorthing}";

   }