ios - 如何从 MKmapview 的可见区域获取半径?

标签 ios swift mkmapview

我能够获得 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/

相关文章:

ios - CollectionViewCell 绘制矩形

ios - 如何将UISearchbar做成矩形并与导航栏合并?

swift - Spritekit SKShapeNode 随机缩放,Swift

swift - 你能用 Swifty-JSON 搜索 JSON 吗?

ios - 在 map View 上显示比例

ios - 具有弯曲边缘和透明状态栏的短 UINavigationBar

ios - 在 Swift 3 中从 UIPageViewController 中删除黑边

ios - 所有 iPad 和 iPad Pro 的 View 之间的常规/常规间距?

objective-c - mapview中的合法标志怎么移动

ios - 重新格式化地标中的字符串结果