> For the complete documentation index, see [llms.txt](https://docs.mapsindoors.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mapsindoors.com/sdks-and-frameworks/ios/displaying-objects/getting-a-polygon-from-a-location.md).

# Getting a Polygon from a Location

Some locations in MapsIndoors can have additional polygon information. These polygons can be used to render a room or area in a special way or make geofences, calculating whether another point or location is contained within the polygon.

If a `MPLocation` has polygons, these can be retrieved using:

```swift
let polygons = location.geometry
let polygon = polygons.first
switch location.geometry?.type {
case "Point":
    let point = location.geometry as? MPPoint
case "Polygon":
    if let polygon = location.geometry as? MPPolygonGeometry, let perimeter = polygon.path {
        for point in perimeter {
            let lat = point.coordinate.latitude
            let long = point.coordinate.longitude
        }
    }

case "MultiPolygon":
    if let multiPolygon = location.geometry as? MPMultiPolygonGeometry {
        // ...
    }
default:
    print("Unsupported geometry")
}
```

As demonstrated above, a polygon's outer ring/path as well as holes are arranged as `[longitude, latitude]` pairs. As not all locations have polygons, the polygon array may be empty. On the contrary, some locations, like entire building floors, might have more than polygon.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mapsindoors.com/sdks-and-frameworks/ios/displaying-objects/getting-a-polygon-from-a-location.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
