首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从TopLeft和BottomRight获得MKCoordinateRegion MKMapView

从TopLeft和BottomRight获得MKCoordinateRegion MKMapView
EN

Stack Overflow用户
提问于 2010-03-17 18:13:12
回答 3查看 5.7K关注 0票数 14

我检查了MKCoordinateRegionMKCoordinateSpanMKMapView文档中的属性,发现有一种方法可以从地图视图中获取TopLeftBottomRight Lat,但我没有找到任何方法。我知道跨度给了我拉特龙三角洲,但是否有办法从地图视图中获得实际的TopLeftBottomRight Lat,而不必进行奇怪的计算?

我找到了this.

不确定这是否足够准确。有票支持吗?

EN

回答 3

Stack Overflow用户

发布于 2010-03-17 23:03:19

我不认为这些计算是奇怪的:

代码语言:javascript
复制
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);
票数 29
EN

Stack Overflow用户

发布于 2016-11-08 16:33:51

SWIFT3.0作为扩展实现了简单的计算:

代码语言:javascript
复制
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)
    }
}

用法:

代码语言:javascript
复制
var region: MKCoordinateRegion = ... some region here
print("North - West", region.northWest)
票数 7
EN

Stack Overflow用户

发布于 2010-08-18 10:53:15

你确定你拿到了+-对吗?我没有得到有用的结果。当我换了+的时候,我换了。也许是我的代码在其他地方有缺陷;)

经度的测量范围为质心子午线0°,东经+180°,西经−180°。希腊字母λ(lambda),3是用来表示地球上一个地方的位置,位于主子午线的东或西。

从技术上讲,纬度是从赤道0°(低纬度)到极地90°(北极90°或+90°,南极90°S或−90°)的角度测量。

(维基百科)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2464729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档