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?