要使用接受northEast和southWest坐标作为“视口”的各种API,有些API会有最大平方英里的搜索限制。
我想计算当前MKMapView缩放级别显示的平方英里。
答案 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;
}