MKPolygon Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/MapKit.framework
Availability
Available in iOS 4.0 and later.
Companion guide
Declared in
MKPolygon.h
Related sample code

Overview

The MKPolygon class represents a shape consisting of one or more points that define a closed polygon. The points are connected end-to-end in the order they are provided. The first and last points are connected to each other to create the closed shape.

When creating a polygon, you can mask out portions of the polygon by specifying one or more interior polygons. For the polygons you specify, this class uses the even-odd fill rule to determine the final occupied area. When applied to overlapping polygons, this rule can cause specific regions to be masked out (and thereby removed) from the total occupied area. For more information about how fill rules are applied to paths, see “Paths” in Quartz 2D Programming Guide.

Tasks

Creating a Polygon Overlay

Accessing the Interior Polygons

Properties

interiorPolygons

The array of polygons nested inside the receiver. (read-only)

@property (readonly) NSArray *interiorPolygons
Discussion

When a polygon is rendered on screen, the area occupied by any interior polygons is masked out and not considered part of the polygon.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKPolygon.h

Class Methods

polygonWithCoordinates:count:

Creates and returns an MKPolygon object from the specified set of coordinates.

+ (MKPolygon *)polygonWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count
Parameters
coords

The array of coordinates defining the shape. The data in this array is copied to the new object.

count

The number of items in the coords array.

Return Value

A new polygon object.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
MKPolygon.h

polygonWithCoordinates:count:interiorPolygons:

Creates and returns an MKPolygon object from the specified set of coordinates and interior polygons.

+ (MKPolygon *)polygonWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count interiorPolygons:(NSArray *)interiorPolygons
Parameters
coords

The array of coordinates defining the shape. The data in this array is copied to the new object.

count

The number of items in the coords array.

interiorPolygons

An array of MKPolygon objects that define one or more cutout regions for the receiver’s polygon.

Return Value

A new polygon object.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
MKPolygon.h

polygonWithPoints:count:

Creates and returns an MKPolygon object from the specified set of map points.

+ (MKPolygon *)polygonWithPoints:(MKMapPoint *)points count:(NSUInteger)count
Parameters
points

The array of map points defining the shape. The data in this array is copied to the new object.

count

The number of items in the points array.

Return Value

A new polygon object.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKPolygon.h

polygonWithPoints:count:interiorPolygons:

Creates and returns an MKPolygon object from the specified set of map points and interior polygons.

+ (MKPolygon *)polygonWithPoints:(MKMapPoint *)points count:(NSUInteger)count interiorPolygons:(NSArray *)interiorPolygons
Parameters
points

The array of map points defining the shape. The data in this array is copied to the new object.

count

The number of items in the points array.

interiorPolygons

An array of MKPolygon objects that define one or more cutout regions for the receiver’s polygon.

Return Value

A new polygon object.

Availability
  • Available in iOS 4.0 and later.
Declared In
MKPolygon.h