如何不用 MKMapView 检测 MKCoordinateRegion 有没有包括 CLLocationCoordinate2D?
我需要检测用户的位置是否属于**MKCoordinateRegion**,但是没有找到解决方法,比如**CGRectContainsCGPoint(rect, point)**。
找到了参考的代码片段:
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));
if (location.latitude < topLeftCoordinate.latitude || location.latitude > bottomRightCoordinate.latitude || location.longitude < bottomRightCoordinate.longitude || location.longitude > bottomRightCoordinate.longitude) {
// Coordinate fits into the region
}
但是不知道是不是精确计算了矩形区域,请高手帮忙解决。谢谢