Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何检查我的坐标是否位于地图可见区域?_Objective C_Iphone_Mkmapview - Fatal编程技术网

Objective c 如何检查我的坐标是否位于地图可见区域?

Objective c 如何检查我的坐标是否位于地图可见区域?,objective-c,iphone,mkmapview,Objective C,Iphone,Mkmapview,我能够在mapview中获得可见区域的东北坐标和西南坐标 但如何检查我的坐标是否位于这些东北坐标和西南坐标之间存在困难 例如,假设我的SW坐标为“38.94271”, “-94.68807”和我的东北坐标为“39.06544300754172”, “-94.57821056524351” 现在我的位置的纬度是22.354643,经度是10.34532,那么我如何检查我的位置是否位于特定区域 + (BOOL)coordinate:(CLLocationCoordinate2D)coord inRe

我能够在mapview中获得可见区域的东北坐标和西南坐标

但如何检查我的坐标是否位于这些东北坐标和西南坐标之间存在困难

例如,假设我的SW坐标为“38.94271”, “-94.68807”和我的东北坐标为“39.06544300754172”, “-94.57821056524351”

现在我的位置的纬度是22.354643,经度是10.34532,那么我如何检查我的位置是否位于特定区域

+ (BOOL)coordinate:(CLLocationCoordinate2D)coord inRegion:(MKCoordinateRegion)region
{
    CLLocationCoordinate2D center = region.center;
    MKCoordinateSpan span = region.span;

    BOOL result = YES;
    result &= cos((center.latitude - coord.latitude)*M_PI/180.0) > cos(span.latitudeDelta/2.0*M_PI/180.0);
    result &= cos((center.longitude - coord.longitude)*M_PI/180.0) > cos(span.longitudeDelta/2.0*M_PI/180.0);
    return result;
}
这应该能奏效。根据你的需要调整它

这应该能奏效。根据你的需要调整它