public function midpoint(Position $from, Position $to): Position
    {
        $lat1 = $from->latitude();
        $lng1 = $from->longitude();
        $lat2 = $to->latitude();
        $lng2 = $to->longitude();

        $lat1 = \deg2rad($lat1);
        $lat2 = \deg2rad($lat2);
        $dLon = \deg2rad($lng2 - $lng1);

        $Bx = \cos($lat2) * \cos($dLon);
        $By = \cos($lat2) * \sin($dLon);

        $lat3 = \atan2(
            \sin($lat1) + \sin($lat2),
            \sqrt((\cos($lat1) + $Bx) * (\cos($lat1) + $Bx) + $By * $By)
        );
        $lon3 = \deg2rad($lng1) + \atan2($By, \cos($lat1) + $Bx);

        return new Position(\rad2deg($lon3), \rad2deg($lat3));
    }
public function midpoint(Position $from, Position $to): Position
    {
        $lat1 = $from->latitude();
        $lng1 = $from->longitude();
        $lat2 = $to->latitude();
        $lng2 = $to->longitude();

        $lat1 = \deg2rad($lat1);
        $lat2 = \deg2rad($lat2);
        $dLon = \deg2rad($lng2 - $lng1);

        $Bx = \cos($lat2) * \cos($dLon);
        $By = \cos($lat2) * \sin($dLon);

        $lat3 = \atan2(
            \sin($lat1) + \sin($lat2),
            \sqrt((\cos($lat1) + $Bx) * (\cos($lat1) + $Bx) + $By * $By)
        );
        $lon3 = \deg2rad($lng1) + \atan2($By, \cos($lat1) + $Bx);

        return new Position(\rad2deg($lon3), \rad2deg($lat3));
    }
public function midpoint ( Position $ from , Position $ to ) : Position { $ lat1 = $ from -> latitude ( ) ; $ lng1 = $ from -> longitude ( ) ; $ lat2 = $ to -> latitude ( ) ; $ lng2 = $ to -> longitude ( ) ; $ lat1 = \ deg2rad ( $ lat1 ) ; $ lat2 = \ deg2rad ( $ lat2 ) ; $ dLon = \ deg2rad ( $ lng2 - $ lng1 ) ; $ Bx = \ cos ( $ lat2 ) * \ cos ( $ dLon ) ; $ By = \ cos ( $ lat2 ) * \ sin ( $ dLon ) ; $ lat3 = \ atan2 ( \ sin ( $ lat1 ) + \ sin ( $ lat2 ) , \ sqrt ( ( \ cos ( $ lat1 ) + $ Bx ) * ( \ cos ( $ lat1 ) + $ Bx ) + $ By * $ By ) ) ; $ lon3 = \ deg2rad ( $ lng1 ) + \ atan2 ( $ By , \ cos ( $ lat1 ) + $ Bx ) ; return new Position ( \ rad2deg ( $ lon3 ) , \ rad2deg ( $ lat3 ) ) ; }
Calculates an intermediate point on the geodesic between the two given
points.

@see http://www.movable-type.co.uk/scripts/latlong.html
Calculates an intermediate point on the geodesic between the two given points .