To get the radius follow this:
- (CLLocationDistance)getRadius
{
CLLocationCoordinate2D centerCoor = [self getCenterCoordinate];
// init center location from center coordinate
CLLocation *centerLocation = [[CLLocation alloc] initWithLatitude:centerCoor.latitude longitude:centerCoor.longitude];
CLLocationCoordinate2D topCenterCoor = [self getTopCenterCoordinate];
CLLocation *topCenterLocation = [[CLLocation alloc] initWithLatitude:topCenterCoor.latitude longitude:topCenterCoor.longitude];
CLLocationDistance radius = [centerLocation distanceFromLocation:topCenterLocation];
return radius;
}
It will return the radius in metres.
To get center coordinate
- (CLLocationCoordinate2D)getCenterCoordinate
{
return [self.mapView centerCoordinate];
}
For getting radius, depends on where you want to get the 2nd point. Lets take the Top Center
- (CLLocationCoordinate2D)getTopCenterCoordinate
{
// to get coordinate from CGPoint of your map
return [self.mapView convertPoint:CGPointMake(self.mapView.frame.size.width / 2.0f, 0) toCoordinateFromView:self.mapView];
}
extension MKMapView{ var topLeftCoordinate: CLLocationCoordinate2D{ return convert(CGPoint.zero, toCoordinateFrom: self) } var radius: CLLocationDistance{ let centerLocation = CLLocation(latitude: centerCoordinate.latitude, longitude: centerCoordinate.longitude) let topLeftLocation = CLLocation(latitude: topLeftCoordinate.latitude, longitude: topLeftCoordinate.longitude) return centerLocation.distance(from: topLeftLocation) } }
– Yarbrough