public static function getCenterOfCoordinates($coords)
    {
        $cnt = count($coords);
        if ($cnt == 0) {
            return null;
        }

        $centerLat = $centerLng = 0;

        foreach ($coords as $coord) {
            if (!($coord instanceof LatLng)) {
                throw new InvalidParamException('$coord must be an array of "' . self::className() . '" objects');
            }
            $centerLat += $coord->getLat();
            $centerLng += $coord->getLng();
        }

        return new self([
            'lat' => ($centerLat / $cnt),
            'lng' => ($centerLng / $cnt)
        ]);
    }
public static function getCenterOfCoordinates($coords)
    {
        $cnt = count($coords);
        if ($cnt == 0) {
            return null;
        }

        $centerLat = $centerLng = 0;

        foreach ($coords as $coord) {
            if (!($coord instanceof LatLng)) {
                throw new InvalidParamException('$coord must be an array of "' . self::className() . '" objects');
            }
            $centerLat += $coord->getLat();
            $centerLng += $coord->getLng();
        }

        return new self([
            'lat' => ($centerLat / $cnt),
            'lng' => ($centerLng / $cnt)
        ]);
    }
public static function getCenterOfCoordinates ( $ coords ) { $ cnt = count ( $ coords ) ; if ( $ cnt == 0 ) { return null ; } $ centerLat = $ centerLng = 0 ; foreach ( $ coords as $ coord ) { if ( ! ( $ coord instanceof LatLng ) ) { throw new InvalidParamException ( '$coord must be an array of "' . self :: className ( ) . '" objects' ) ; } $ centerLat += $ coord -> getLat ( ) ; $ centerLng += $ coord -> getLng ( ) ; } return new self ( [ 'lat' => ( $ centerLat / $ cnt ) , 'lng' => ( $ centerLng / $ cnt ) ] ) ; }
Calculates the center of an array of coordinates

@param LatLng[] $coords

@throws \yii\base\InvalidParamException
@return LatLng|null
Calculates the center of an array of coordinates