何时/何处开始更新位置?
位置的确定需要一些时间。位置管理器应该在何时何地启动?
现在,我在加载结果视图(需要位置)之前开始更新一个视图的位置。如果用户快速点击,我会得到 0.0 坐标。
为了获得正确的时机,应该在结果视图之前调用 startUpdatingLocation
三个视图。这里的问题是我必须通过这三个视图控制器传递值。
接下来的事情是我还需要另一个视图中的位置(不是上面提到的视图)。我想我会创建一个自己的位置侦听器类。但是这个类什么时候会被实例化并传递坐标(经度、纬度)呢?协议对我没有帮助,因为只有创建我的位置侦听器的类才能获取结果。
我读了一点并提出了以下可能的解决方案:
1)使用通知中心(请参阅此解决方案)
2)在AppDelegate
中创建我的位置管理器的属性
1)我会遇到需要结果的视图的问题之前不会被创建。
2) 的实施会是什么样子?我在应用程序委托中创建位置管理器的实例,然后访问一些 ivars,例如 AppDelegate 的纬度/经度?如果我采用此处描述的解决方案,我将必须实施每次CLLocationManagerDelegate
。开设一堂课来完成这项工作不是更好吗?
也许您有第三种解决方案?
The determination of a position takes some time. When and where should the location manager be started?
Now I'm starting the location update one view before the result view (which needs the location) is loaded. If the user taps to fast I get 0.0 coordinates.
To get the right timing the startUpdatingLocation
should be called three views before the result view. The problem here is I would have to pass the value trough this three view controllers.
The next thing is that I need the location also in another view (not the views mentioned above). I thought I will create an own location listener class. But when will this class be instantiated and the coordinates (longitude, latitude) passed through? A protocol doesn't help me, because only the class which created my location listener will get the results back.
I read a bit and come up with the following possible solutions:
1) Use of the Notification Center (see this solution)
2) Create a property of my location manager in the AppDelegate
At 1) I would have the problem that the view, which needs the results wouldn't have be created before.
How would the implementation of 2) would look like? I create an instance of the location manager in the app delegate and then I access some ivars like latitude/longitude of the AppDelegate
? If I would take the solution described here I would have to implement the CLLocationManagerDelegate
every time. Wouldn't it be better to have one class for doing that?
Perhaps you have a third solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第三种解决方案可能是使用单例类,将位置的纬度和经度存储在 CLLocationCooperative2D 中。然后,您可以使用以下代码从项目中的任何视图访问存储的坐标
A third solution may be to use a singleton class where you store the latitude and longitude of the location in a CLLocationCoordinate2D. You can then use the following code to access the stored coordinate from any view in your project