Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check MKMapView contains CLLocationCoordinate2D
MKCoordinateRegion region = mapView.region;
CLLocationCoordinate2D topLeftCoordinate =
CLLocationCoordinate2DMake(region.center.latitude + (region.span.latitudeDelta / 2.0),
region.center.longitude - (region.span.longitudeDelta / 2.0));
CLLocationCoordinate2D bottomRightCoordinate =
CLLocationCoordinate2DMake(region.center.latitude - (region.span.latitudeDelta / 2.0),
region.center.longitude + (region.span.longitudeDelta / 2.0));
MKMapPoint topLeftMapPoint = MKMapPointForCoordinate(topLeftCoordinate);
MKMapPoint bottomRightMapPoint = MKMapPointForCoordinate(bottomRightCoordinate);
MKMapRect mapRect = MKMapRectMake(topLeftMapPoint.x, topLeftMapPoint.y,
fabs(bottomRightMapPoint.x - topLeftMapPoint.x), fabs(bottomRightMapPoint.y - topLeftMapPoint.y));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment