从 MKCooperativeRegion MKMapView 获取 TopLeft 和 BottomRight

发布于 2024-08-25 03:45:52 字数 485 浏览 3 评论 0原文

我检查了 MKCooperativeRegionMKCooperativeSpanMKMapView 的文档中的属性,看看有没有一种方法可以获取 TopLeftBottomRight Lat Long 从地图视图来看,我没有找到任何东西。我知道跨度给了我纬度长增量,但有没有办法从地图视图中获取实际的 TopLeftBottomRight 纬度经度,而不必进行奇怪的计算?

我发现 这个。

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

I checked the properties in documentation for MKCoordinateRegion, MKCoordinateSpan and MKMapView to see there is a way to get the TopLeft and BottomRight Lat Long from the map view and I didn't find any. I know that the span gives me the Lat long delta but is there a way to get the actual TopLeft and BottomRight lat longs from map view without having to do weird calculations?

I found this.

Not sure if that is accurate enough. Any votes for that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

開玄 2024-09-01 03:45:52

我不认为这些计算有什么奇怪的:

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);

I don't think these calculations qualify as weird:

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);
思慕 2024-09-01 03:45:52

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)

Straightforward calculations implemented in Swift 3.0 as extension:

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)
    }
}

Usage:

var region: MKCoordinateRegion = ... some region here
print("North - West", region.northWest)
还在原地等你 2024-09-01 03:45:52

你确定你的+-正确吗?我没有得到有用的结果。当我切换+-时,我做到了。不过,我的代码可能在其他地方存在缺陷;)

经度是以角度测量形式给出的,范围从本初子午线的 0° 到向东 +180° 和向西 -180°。希腊字母 λ (lambda),[3][4] 用于表示地球上本初子午线以东或以西的某个地点的位置。

从技术上讲,纬度是以度为单位的角度测量值(用 ° 标记),范围从赤道 0°(低纬度)到极地 90°(北极为 90° N 或 +90°,南纬 90° 或 −90 ° 为南极)。

(维基百科)

Are you sure you got the +- right? I did not get useful results with that. When I switched the +-, I did. Might be my code is flawed somewhere else, though ;)

Longitude is given as an angular measurement ranging from 0° at the Prime Meridian to +180° eastward and −180° westward. The Greek letter λ (lambda),[3][4] is used to denote the location of a place on Earth east or west of the Prime Meridian.

Technically, latitude is an angular measurement in degrees (marked with °) ranging from 0° at the equator (low latitude) to 90° at the poles (90° N or +90° for the North Pole and 90° S or −90° for the South Pole).

(Wikipedia)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文