I'm trying to see if some extents (max x, max y, min x, min y coordinates) I have are in the current visible map view.
I take my extents and create a MKMapRect
:
MKMapPoint upperLeft = MKMapPointForCoordinate(CLLocationCoordinate2DMake([boundary.extents.maxY floatValue], [boundary.extents.minY floatValue]));
MKMapPoint lowerLeft = MKMapPointForCoordinate(CLLocationCoordinate2DMake([boundary.extents.minY floatValue], [boundary.extents.minY floatValue]));
MKMapPoint upperRight = MKMapPointForCoordinate(CLLocationCoordinate2DMake([boundary.extents.maxY floatValue], [boundary.extents.maxY floatValue]));
MKMapRect mapRect = MKMapRectMake(upperLeft.x, upperLeft.y, fabs(upperLeft.x - upperRight.x), fabs(upperLeft.y - lowerLeft.y));
Now I want to check if my 'mapRect' is in the mapView.visibleMapRect:
if (MKMapRectContainsRect(mapView.visibleMapRect, mapRect)) {
// do some stuff
}
But my extents are never contained by the mapView.visibleMapRect
when I know they should be.
If I replace the mapView.visibleMapRect
with MKMapRectWorld
, then it will contain my extents 'mapRect'.
Am I doing something wrong? is mapView.visibleMapRect
not what I think it is (the viewable area on the screen)?
D'oh!
The issue was that I used minY instead of minX.