在 iOS 上使用 GPS 的正确方法
我正在尝试在我的应用程序中实现 GPS 的使用,但我不确定执行此操作的正确方法。
我的应用程序具有以下设计: * 主页带有一些重定向到以下视图的按钮: - 位置列表(距当前位置的距离) - 所选位置的详细信息(距当前位置的距离) - 地图(包含所选位置的详细信息)
我已经在地图视图中实现了 CLLocationManagerDelegate,但我知道我也需要其他视图中的当前位置来计算距离。 最好的方法是什么?我是否必须支持 CLLocationManagerDelegate 并计算每个视图中的当前位置?或者也许我必须仅在主页中支持委托并将当前位置存储在全局变量中?
建议将非常感激!
谢谢, 亚萨
I'm trying to implement the use of gps in my app, but I'm not sure about the right approach for doing this.
My app has the following design:
* home page with some buttons that redirect to the following views:
- list of locations (with distance from the current position)
- detail of selected location (with distance from the current position)
- map (with detail of the selected location)
I've implemented the CLLocationManagerDelegate in the map view, but I understand that I need the current position also in the other views to calculate distances.
What is the best approach? Do I have to support the CLLocationManagerDelegate and calculate current position in each view? Or maybe do I have to support the delegate only in my homepage and store the current location in a global variable?
Suggestions will be really appreciated!!
Thanks,
yassa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说最好的方法是将 CLLocationManagerDelegate 实现为单例类,以便您可以在应用程序中的任何位置引用它。
The best way for me is to implement the CLLocationManagerDelegate as a singleton class, so that you can refer to it everywhere in your app.