健全性检查 MKCo整理区域
有什么方法可以快速测试 MKCooperativeRegion
是否良好?我将纬度换成了经度并导致应用程序崩溃。我希望能够在实际执行之前看看是否可以执行 setRegion
。 MKCooperativeRegionMake
会测试我给它的值吗?
谢谢。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原来我在某个地方交换了纬度和经度。这是我最终使用的代码:
It turns out I had swapped my latitude and longitude somewhere. Here's the code I ended up using:
我没有太多地摆弄地图,所以对此持保留态度。
听起来您需要在使用纬度、经度和跨度值之前对其进行范围检查。
在所有情况下,纬度和经度的值都应在 -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.