健全性检查 MKCo整理区域

发布于 2024-08-20 11:50:29 字数 181 浏览 4 评论 0原文

有什么方法可以快速测试 MKCooperativeRegion 是否良好?我将纬度换成了经度并导致应用程序崩溃。我希望能够在实际执行之前看看是否可以执行 setRegionMKCooperativeRegionMake 会测试我给它的值吗?

谢谢。

Is there any way to quickly test whether an MKCoordinateRegion is good or not? I've swapped latitude for longitude and caused an application crash. I'd like to be able to see whether it's possible to perform a setRegion before I actually do it. Will MKCoordinateRegionMake test the values I give it?

Thanks.

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

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

发布评论

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

评论(2

别把无礼当个性 2024-08-27 11:50:29

原来我在某个地方交换了纬度和经度。这是我最终使用的代码:

// check for sane span values
if (currentRegion.span.latitudeDelta <= 0.0f || currentRegion.span.longitudeDelta <= 0.0f) {
    currentRegion.span.latitudeDelta = 1.0f;
    currentRegion.span.longitudeDelta = 1.0f;
}
// check for sane center values
if (currentRegion.center.latitude > 90.0f || currentRegion.center.latitude < -90.0f ||
    currentRegion.center.longitude > 180.0f || currentRegion.center.longitude < -180.0f
    ) {
    // Take me to Tokyo.
    currentRegion.center.latitude = 35.4f;
    currentRegion.center.longitude = 139.4f;
}

It turns out I had swapped my latitude and longitude somewhere. Here's the code I ended up using:

// check for sane span values
if (currentRegion.span.latitudeDelta <= 0.0f || currentRegion.span.longitudeDelta <= 0.0f) {
    currentRegion.span.latitudeDelta = 1.0f;
    currentRegion.span.longitudeDelta = 1.0f;
}
// check for sane center values
if (currentRegion.center.latitude > 90.0f || currentRegion.center.latitude < -90.0f ||
    currentRegion.center.longitude > 180.0f || currentRegion.center.longitude < -180.0f
    ) {
    // Take me to Tokyo.
    currentRegion.center.latitude = 35.4f;
    currentRegion.center.longitude = 139.4f;
}
挽容 2024-08-27 11:50:29

我没有太多地摆弄地图,所以对此持保留态度。

听起来您需要在使用纬度、经度和跨度值之前对其进行范围检查。 在所有情况下,纬度和经度的值都应在 -180 到 180 之间。

Edit01:

我认为交换纬度和经度不会导致崩溃。它们都具有完全相同的单位(度)和范围(-180→180)。所有有效的纬度值也是有效的经度值,反之亦然。出于这个原因,MKCooperativeRegionMake 将无法知道您已经交换了这些值,因为它们仍然是有效的坐标,只是不在您想要的位置附近。

我认为你的问题在其他地方。

I haven't fiddle with the map much so take this with a grain of salt.

It sounds like you need to put a range check on your values for latitude, longitude and span before you use them. Latitude and longitude should in all cases have values between -180 and 180.

Edit01:

I don't think that swapping latitude and longitude could cause a crash. They both have exactly the same units (degrees) and ranges(-180-->180). All valid values of latitude are also valid values for longitude and vice versa. For this reason, MKCoordinateRegionMake won't be able to tell that you've swapped the values because they would still be valid coordinates, just not anywhere near where you wanted.

I think your problem is elsewhere.

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