I have two different UIViewControllers that need access to the user’s Latitude and Longitude. I only need to access the location once when the view appears. I am currently storing the LocationManager in the app delegate, but the viewDidAppear: method loads too quickly for the user’s location to be found. Does anyone know the best way to go about this? Thank you!
I have two different UIViewControllers that need access to the user’s Latitude and Longitude
Share
I create a shared
LocationManager. ThenstartUpdatingLocationandstopUpdatingLocationafter you get a callback.Here is the code I use:
In your
appDelegateadd the following method:And make the LocationManager available:
Then in your UIViewController you can do:
Then I use the following code to get the location and display it in a UILabel.
Important is the last line
stopUpdatingLocationso theLocationManageronly gets called once.