为什么 MKCoordinateSpan 会改变?

发布于 2024-08-26 18:33:44 字数 497 浏览 5 评论 0原文

当我调试下面的代码时,我发现 mapkit 更改了我提供的跨度。 span2 包含与提供的数字不同的数字。为什么会发生这种情况?

- (void) viewDidLoad
{
    [super viewDidLoad];

    CLLocationCoordinate2D loc;
    loc.latitude = self.atm.lat;
    loc.longitude = self.atm.lon;

    MKCoordinateSpan span1 = MKCoordinateSpanMake(0.05f, 0.05f);
    self.mapView.region = MKCoordinateRegionMake(loc, span1);
    // at this point numbers are not 0.05 anymore
    MKCoordinateSpan span2 = self.mapView.region.span;
// ... more code
}

When I debug code below, I see that span is changed by mapkit from what I have provided. span2 contains different numbers from what was provided. Why is this happening?

- (void) viewDidLoad
{
    [super viewDidLoad];

    CLLocationCoordinate2D loc;
    loc.latitude = self.atm.lat;
    loc.longitude = self.atm.lon;

    MKCoordinateSpan span1 = MKCoordinateSpanMake(0.05f, 0.05f);
    self.mapView.region = MKCoordinateRegionMake(loc, span1);
    // at this point numbers are not 0.05 anymore
    MKCoordinateSpan span2 = self.mapView.region.span;
// ... more code
}

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

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

发布评论

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

评论(2

北座城市 2024-09-02 18:33:44

请注意,纬度和经度的变化不同,因此方形 MapView 实际上将显示其坐标具有不同跨度值的区域。这可能会导致您的地图视图区域的跨度(稍微?)与您设置的不同。

在 MKMapView 的区域属性的参考中,有一些相关的短语:

只改变区域的中心坐标仍然可以
导致跨度隐式改变。
这是因为
由跨度变化表示的距离
在不同的纬度和经度
并且地图视图可能需要调整
考虑新的跨度
位置。

Note that latitude and longitude change differently so square MapView will actually display region with different span values for its coordinates. This is likely to cause your mapview region to have span (slightly?) different from what you set.

In reference for MKMapView's region property there's somewhat relevant phrase:

Changing only the center coordinate of the region can still
cause the span to change implicitly.
This is due to the fact that the
distances represented by a span change
at different latitudes and longitudes
and the map view may need to adjust
the span to account for the new
location.

盗琴音 2024-09-02 18:33:44

具有相同纬度和经度跨度值的方形 MapView 几乎总是会经历上面所示的跨度变化,因为当您从赤道移动到任一极时,纵向弧长会发生显着变化。当纬度接近+/-90时,纵向弧长接近0。

然而,此外,如果MapView区域不是正方形,相同的跨度值也会改变(因为跨度仅指当时实际可见的区域) 。

A square MapView with identical values for the latitudinal and longitudinal span will almost always experience the change in span indicated above as longitudinal arc-length varies significantly as you move from the equator to either pole. As the latitude approaches +/-90, the longitudinal arc-length approaches 0.

In addition, however, identical span values will also change if the MapView region is not square (as the span only refers to the region actually visible at the time).

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