MKMapView - 如何计算当前视图中的平方英里数

时间:2011-12-16 08:11:51

标签: ios mkmapview

要使用接受northEast和southWest坐标作为“视口”的各种API,有些API会有最大平方英里的搜索限制。

我想计算当前MKMapView缩放级别显示的平方英里。

1 个答案:

答案 0 :(得分:1)

以下是解决方案:

- (float)numSquareMiles
{
    CLLocationCoordinate2D northEast, southWest;
    northEast = [mapView convertPoint:CGPointMake(mapView.frame.size.width, 0) toCoordinateFromView:mapView];
    southWest = [mapView convertPoint:CGPointMake(0, mapView.frame.size.height) toCoordinateFromView:mapView];


    float distanceLatInDegrees = northEast.latitude - southWest.latitude;
    float numLatMiles = 69.172 * distanceLatInDegrees;

    float distanceLonInDegrees = northEast.longitude - southWest.longitude;
    float numLonMiles = 69.172 * distanceLonInDegrees;

    float numSquareMiles = numLatMiles*numLonMiles;

    return numSquareMiles;
}