我能够获得 map View 的可见矩形以及 map View 的中心点和跨度增量也可以从 mkmaap View 方法中获得:
要获得可见性,请使用:mapView.visibleMapRect
。获取中心点:使用 map view.centerCoordinate
获取跨度:使用 mapView.region.span
。
现在我有了所有的信息,我如何计算可见半径正在使用计算?谁能详细解释一下?
我看过this question但答案是给我跨度而不是可见区域的半径。
最佳答案
要获取半径,请执行以下操作:
- (CLLocationDistance)getRadius
{
CLLocationCoordinate2D centerCoor = [self getCenterCoordinate];
// init center location from center coordinate
CLLocation *centerLocation = [[CLLocation alloc] initWithLatitude:centerCoor.latitude longitude:centerCoor.longitude];
CLLocationCoordinate2D topCenterCoor = [self getTopCenterCoordinate];
CLLocation *topCenterLocation = [[CLLocation alloc] initWithLatitude:topCenterCoor.latitude longitude:topCenterCoor.longitude];
CLLocationDistance radius = [centerLocation distanceFromLocation:topCenterLocation];
return radius;
}
它将返回以米为单位的半径。
获取中心坐标
- (CLLocationCoordinate2D)getCenterCoordinate
{
return [self.mapView centerCoordinate];
}
要获取半径,取决于您要获取第二个点的位置。让我们以顶部中心
为例- (CLLocationCoordinate2D)getTopCenterCoordinate
{
// to get coordinate from CGPoint of your map
return [self.mapView convertPoint:CGPointMake(self.mapView.frame.size.width / 2.0f, 0) toCoordinateFromView:self.mapView];
}
关于ios - 如何从 MKmapview 的可见区域获取半径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29093843/