Iphone 如何找到MKMapView可见屏幕区域的半径?

Iphone 如何找到MKMapView可见屏幕区域的半径?,iphone,objective-c,mkmapview,mapkit,Iphone,Objective C,Mkmapview,Mapkit,我想知道iphone屏幕上可见区域的半径,因为我将缩放可见区域,因此我想知道该特定区域的半径,我该怎么做?它的半径不是所需的半径 您需要使用mapView中的“区域”参数 看看苹果的文档,这些文档非常清晰 浏览本教程。这对你会有很大帮助 具体来说,您需要设置如下内容 MKCoordinateSpan span = [self coordinateSpanWithMapView:self centerCoordinate:centerCoordinate andZoomLevel:zoomLev

我想知道iphone屏幕上可见区域的半径,因为我将缩放可见区域,因此我想知道该特定区域的半径,我该怎么做?

它的半径不是所需的半径

您需要使用mapView中的“区域”参数

看看苹果的文档,这些文档非常清晰

浏览本教程。这对你会有很大帮助

具体来说,您需要设置如下内容

MKCoordinateSpan span = [self coordinateSpanWithMapView:self centerCoordinate:centerCoordinate andZoomLevel:zoomLevel];
MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate, span);
[self setRegion:region animated:animated];
其中跨度可计算为

- (MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mapView
                         centerCoordinate:(CLLocationCoordinate2D)centerCoordinate
                             andZoomLevel:(NSUInteger)zoomLevel
{
// convert center coordiate to pixel space
double centerPixelX = [self longitudeToPixelSpaceX:centerCoordinate.longitude];
double centerPixelY = [self latitudeToPixelSpaceY:centerCoordinate.latitude];

// determine the scale value from the zoom level
NSInteger zoomExponent = 20 - zoomLevel;
double zoomScale = pow(2, zoomExponent);

// scale the map’s size in pixel space
CGSize mapSizeInPixels = mapView.bounds.size;
double scaledMapWidth = mapSizeInPixels.width * zoomScale;
double scaledMapHeight = mapSizeInPixels.height * zoomScale;

// figure out the position of the top-left pixel
double topLeftPixelX = centerPixelX - (scaledMapWidth / 2);
double topLeftPixelY = centerPixelY - (scaledMapHeight / 2);

// find delta between left and right longitudes
CLLocationDegrees minLng = [self pixelSpaceXToLongitude:topLeftPixelX];
CLLocationDegrees maxLng = [self pixelSpaceXToLongitude:topLeftPixelX + scaledMapWidth];
CLLocationDegrees longitudeDelta = maxLng - minLng;

// find delta between top and bottom latitudes
CLLocationDegrees minLat = [self pixelSpaceYToLatitude:topLeftPixelY];
CLLocationDegrees maxLat = [self pixelSpaceYToLatitude:topLeftPixelY + scaledMapHeight];
CLLocationDegrees latitudeDelta = -1 * (maxLat - minLat);

// create and return the lat/lng span
MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta, longitudeDelta);
return span;
}

干杯:)

我可能误解了这个问题,但这不是很简单吗

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    CGFloat latD = mapView.region.span.latitudeDelta;
    CGFloat lngD = mapView.region.span.longitudeDelta;
    NSLog(@"This is the latitude delta of the visible map: %f", latD);
    NSLog(@"This is the longitude delta of the visible map: %f", lngD);
}

Swapz,我肯定会的,因为我会测试,它会起作用,否则我会回复你亲爱的我有不同的场景,我必须发送区域半径,然后服务器将返回该地区办公室的数据,所以我可能需要半径,否则必须以不同的方式更改xml。。当您更改区域和跨度时,再次发送经纬度参数,服务器将返回与这些区域对应的对象。例如,检查Google ReqVersegeCoding api,它的工作方式与您可以引用的方式相同。这意味着我无法获取可见MKMapView的半径,您确定吗?当您更改区域和跨度时,再次发送经纬度参数,服务器将返回与这些区域对应的对象。例如,检查Google ReqVersegoCoding api,它的工作方式与您可以引用的方式相同。在这里查看查看反向地理编码(地址查找)部分。您找到解决方案了吗?请告诉我,我有相同的senario