Ios 如何计算MKMapView中可见区域的半径?

Ios 如何计算MKMapView中可见区域的半径?,ios,swift,mapkit,quickblox,Ios,Swift,Mapkit,Quickblox,我正在使用QuickBlox,我有一个地图,可以根据用户的位置进行更新 我正在获取用户的位置,并使用“QBRequest.geoDataWithFilter”函数将其放置在地图上。 我正在创建一个具有半径值的过滤器。我还使用了mapView(mapView:MKMapView!,regiondidchangearnimated:Bool)功能来检测区域何时发生了更改 用户的位置会定期更新,并根据用户的位置(登录的用户)而不是可视区域从服务器接收,因此我不关心地图的中心 我希望在缩小时能够加载更多

我正在使用QuickBlox,我有一个地图,可以根据用户的位置进行更新

我正在获取用户的位置,并使用“QBRequest.geoDataWithFilter”函数将其放置在地图上。 我正在创建一个具有半径值的过滤器。我还使用了
mapView(mapView:MKMapView!,regiondidchangearnimated:Bool)
功能来检测区域何时发生了更改

用户的位置会定期更新,并根据用户的位置(登录的用户)而不是可视区域从服务器接收,因此我不关心地图的中心

我希望在缩小时能够加载更多用户,因此每次用户缩小时半径都应该增加,如果用户正在放大,半径应该减小

如何使用地图的跨度计算地图上可见区域的半径?(如果可能的话,我只需要这个等式)


提前感谢。

这不是所需的半径

您需要使用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;
}

检查这个:是的,我见过这个问题,但问题是我需要以米为单位的半径。这就是geoDataWithFilter函数的工作原理。我是否有可能或者应该寻找另一种方式?