How to find nearest distance between user's location and a polygon shape in swift?

167 Views Asked by At

The following code fragments determine whether an MKMapPoint located inside or outside a polygon, but I'm asking if there is any way to find the nearest distance in meters or amount of time between that point and the polygon where the polygon formed by using geoJSON coordinates?

let renderer = MKPolygonRenderer(polygon: polygon)
let mapPoint: MKMapPoint = MKMapPoint(CLLocationCoordinate2D(latitude: lat, longitude: long))
let polygonViewPoint: CGPoint = renderer.point(for: mapPoint)
if renderer.path.contains(polygonViewPoint) {
   print(" Inside polygon")
} else {
   print(" Outside polygon.")
}
0

There are 0 best solutions below