我检查了文档中的属性MKCoordinateRegion,MKCoordinateSpan并MKMapView查看有一种方法可以从地图视图中获取TopLeft和BottomRight Lat Long,但我没有找到任何方法。我知道跨度给了我 Lat long delta 但是有没有办法从地图视图中获取实际的TopLeft和BottomRight lat longs 而无需进行奇怪的计算?
我发现了这个。
不确定这是否足够准确。对此有任何投票吗?
我检查了文档中的属性MKCoordinateRegion,MKCoordinateSpan并MKMapView查看有一种方法可以从地图视图中获取TopLeft和BottomRight Lat Long,但我没有找到任何方法。我知道跨度给了我 Lat long delta 但是有没有办法从地图视图中获取实际的TopLeft和BottomRight lat longs 而无需进行奇怪的计算?
我发现了这个。
不确定这是否足够准确。对此有任何投票吗?
我认为这些计算并不奇怪:
CLLocationCoordinate2D center = region.center;
CLLocationCoordinate2D northWestCorner, southEastCorner;
northWestCorner.latitude = center.latitude + (region.span.latitudeDelta / 2.0);
northWestCorner.longitude = center.longitude - (region.span.longitudeDelta / 2.0);
southEastCorner.latitude = center.latitude - (region.span.latitudeDelta / 2.0);
southEastCorner.longitude = center.longitude + (region.span.longitudeDelta / 2.0);
在Swift 3.0中作为扩展实现的简单计算:
extension MKCoordinateRegion {
var northWest: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: center.latitude + span.latitudeDelta / 2,
longitude: center.longitude - span.longitudeDelta / 2)
}
var northEast: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: center.latitude + span.latitudeDelta / 2,
longitude: center.longitude + span.longitudeDelta / 2)
}
var southWest: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: center.latitude - span.latitudeDelta / 2,
longitude: center.longitude - span.longitudeDelta / 2)
}
var southEast: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: center.latitude - span.latitudeDelta / 2,
longitude: center.longitude + span.longitudeDelta / 2)
}
}
用法:
var region: MKCoordinateRegion = ... some region here
print("North - West", region.northWest)
你确定你得到了+-对吗?我没有得到有用的结果。当我切换+-时,我做到了。不过,可能是我的代码在其他地方有缺陷;)
经度以角度测量值给出,范围从本初子午线的 0° 到向东 +180° 和向西 -180°。希腊字母 λ (lambda),[3][4] 用于表示地球上本初子午线以东或以西的位置。
从技术上讲,纬度是以度为单位的角度测量值(标记为°),范围从赤道(低纬度)的 0° 到两极的 90°(北极的 90° N 或 +90° 和 90° S 或 -90 °为南极)。
(维基百科)