Getting a Polygon from a Location
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++
}
}
}Last updated
Was this helpful?