【发布时间】:2018-05-20 16:45:00
【问题描述】:
我有一个我配置的 MKMapView:
static let STARTING_MAP_RANGE: Double = 1000 // meters
. . .
let region: MKCoordinateRegion = MKCoordinateRegionMakeWithDistance(location,
MapViewController.STARTING_MAP_RANGE,
MapViewController.STARTING_MAP_RANGE)
mapView.setRegion(region, animated: true)
我为当前位置添加了注释,一切看起来都很好。当我为可见区域中的其他点添加注释时,MKMapView 会放大到显示所有注释所需的最小区域。
奇怪的是,我试图通过打印左下角和右上角的纬度和经度来找出发生这种情况的位置,如下所示:
private func printMapRegion(caller: String)
{
let mapRect = mapView.visibleMapRect;
let bottomLeft = MKCoordinateForMapPoint(MKMapPointMake(mapRect.origin.x, MKMapRectGetMaxY(mapRect)))
let topRight = MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMaxX(mapRect), mapRect.origin.y))
print("\(caller): (\(bottomLeft.latitude),\(bottomLeft.longitude)) -- (\(topRight.latitude),\(topRight.longitude))")
}
当我在设置注释之前和之后运行它时,我得到相同的值,尽管在屏幕上看到地图缩放(在模拟器和我的 iPhone 中)。
我添加了一个刷新按钮来重置地图。它可以将地图缩小,但它还报告左下角和右上角的坐标在缩放之前和之后是相同的。
我对 visibleMapRect 的理解有问题吗?
【问题讨论】: