Getting the bounds of an MKMapView

前端 未结 10 1127
既然无缘
既然无缘 2020-11-28 20:28

In order to setup a query to an external server I want to get the bounds of the current Map View in an iPhone app I\'m building. UIView should respond to bounds but it seems

10条回答
  •  天命终不由人
    2020-11-28 20:42

    I was having some trouble with some of the other answers for maps that had been 2 finger rotated. This code worked for me:

    MKMapRect rect = self.mapView.visibleMapRect;
    CLLocationCoordinate2D northeast = MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMaxX(rect),rect.origin.y));
    CLLocationCoordinate2D southwest = MKCoordinateForMapPoint(MKMapPointMake(rect.origin.x         ,MKMapRectGetMaxY(rect)));
    

    My answer is derived from 陈保状's answer and the associated website enter link description here. Its simplified down too 3 lines for south west and north east corners.

提交回复
热议问题