I am drawing a MKCircle
on MKMapView
, I need to get all points in the Circle border (not inside it) to send the points coordinates to server and get the information that related to the region which is inside the circle.
Also as I have the center coordinate
and radius
of circle So maybe points could be calculated by this variables.
How can I get the points coordinates ?
I calculated the points, But as you know we can't get ALL the points, But this method returns about 40 points of the circle that is enough.
internal func radiusSearchPoints(coordinate: CLLocationCoordinate2D, radius: CLLocationDistance) -> [CLLocationCoordinate2D] {
var points: [CLLocationCoordinate2D] = []
let earthRadius = 6_378_100.0
let π = Double.pi
let lat = coordinate.latitude * π / 180.0
let lng = coordinate.longitude * π / 180.0
var t: Double = 0
while t <= 2 * π {
let pointLat = lat + (radius / earthRadius) * sin(t)
let pointLng = lng + (radius / earthRadius) * cos(t)
let point = CLLocationCoordinate2D(latitude: pointLat * 180 / π, longitude: pointLng * 180 / π)
points.append(point)
t += 0.3
}
return points
}