我检查了MKCoordinateRegion、MKCoordinateSpan和MKMapView文档中的属性,发现有一种方法可以从地图视图中获取TopLeft和BottomRight Lat,但我没有找到任何方法。我知道跨度给了我拉特龙三角洲,但是否有办法从地图视图中获得实际的TopLeft和BottomRight Lat,而不必进行奇怪的计算?
我找到了this.
不确定这是否足够准确。有票支持吗?
发布于 2010-03-17 23:03:19
我不认为这些计算是奇怪的:
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);发布于 2016-11-08 16:33:51
在SWIFT3.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)发布于 2010-08-18 10:53:15
你确定你拿到了+-对吗?我没有得到有用的结果。当我换了+的时候,我换了。也许是我的代码在其他地方有缺陷;)
经度的测量范围为质心子午线0°,东经+180°,西经−180°。希腊字母λ(lambda),3是用来表示地球上一个地方的位置,位于主子午线的东或西。
从技术上讲,纬度是从赤道0°(低纬度)到极地90°(北极90°或+90°,南极90°S或−90°)的角度测量。
(维基百科)
https://stackoverflow.com/questions/2464729
复制相似问题