# 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:

```kotlin
val geometry: MPGeometry = location.geometry
when (geometry.iType) {
    MPGeometry.TYPE_POINT -> {
        val point = geometry
    }
    MPGeometry.TYPE_POLYGON -> {
        val polygon: MPPolygonGeometry = geometry as MPPolygonGeometry
        // Using GMS helper classes
        // Get all the paths in the polygon
        val paths: List<List<MPLatLng>> = polygon.gmsPath
        val pathCount = paths.size
        // Outer ring (first)
        val path = paths[0]
        for (coordinate in path) {
            val lat = coordinate.lat
            val lng = coordinate.lng
        }
        // Optional: Inner rings (holes)
        var i = 1
        while (i < pathCount) {
            val hole = paths[i]
            for (coordinate in hole) {
                val lat = coordinate.lat
                val lng = coordinate.lng
            }
            i++
        }
    }
}
```

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


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
