如何确定当前用户位置是否在我的MKCoordinateRegion内?

Ala*_*ore 7 gps mapkit mkcoordinateregion userlocation ios5

我有一个我确定的坐标区域包含我想要为我的应用程序显示的限制.我把它设置为MKCoordinateRegion,中心点为lat,经度和跨度.如何确定当前userLocation是否在我的坐标区域内?

fir*_*der 9

使用地图rects.这是使用地图当前可见矩形的示例.关于您的问题,您可以使用convertRegion:toRectToView:先将您的区域转换为MKMapRect预先.

MKMapPoint userPoint = MKMapPointForCoordinate(mapView.userLocation.location.coordinate);
MKMapRect mapRect = mapView.visibleMapRect;
BOOL inside = MKMapRectContainsPoint(mapRect, userPoint);
Run Code Online (Sandbox Code Playgroud)