---
title: "union(_:)"
framework: mapkit
role: symbol
role_heading: Instance Method
path: "mapkit/mkmaprect/union(_:)"
---

# union(_:)

Returns a rectangle that represents the union of two rectangles.

## Declaration

```swift
func union(_ rect2: MKMapRect) -> MKMapRect
```

## Parameters

- `rect2`: The second rectangle.

## Return Value

Return Value A rectangle with an area that encompasses the two rectangles and the space between them.

## Discussion

Discussion If either rectangle is null, this method returns the other rectangle. This method sets the origin point of the returned rectangle to the smaller of the x and y values for the two rectangles. Similarly, the method computes the size and width of the rectangle by taking the maximum x and y values and subtracting the x and y values for the new origin point.

## See Also

### Modifying the rectangle

- [intersection(_:)](mapkit/mkmaprect/intersection(_:).md)
- [insetBy(dx:dy:)](mapkit/mkmaprect/insetby(dx:dy:).md)
- [offsetBy(dx:dy:)](mapkit/mkmaprect/offsetby(dx:dy:).md)
- [MKMapRectDivide(_:_:_:_:_:)](mapkit/mkmaprectdivide(_:_:_:_:_:).md)
