views:

239

answers:

1

What I can do: Take a sqlite DB of 100 lat and lng points, and drop those pins on a map. Looks GREAT!

What I would like to do is get my location, BEFORE I draw my map. But it seems that:

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

ALWAYS fires off AFTER (void)viewDidLoad runs. NO MATTER where I insert it.

What i need to do is have a splash screen, STOP there until I get a location, use that lat and lng to search my sqlite DB of locations within so many miles of me.

Here my trace:

Entering -[RootViewController initWithTabBar]

Entering -[RootViewController viewDidLoad]

Entering -[RootViewController locationManager:didUpdateToLocation:fromLocation:]

And here's what I really want:

Entering -[RootViewController initWithTabBar]

Entering -[RootViewController locationManager:didUpdateToLocation:fromLocation:]

Entering -[RootViewController viewDidLoad]

Now I'm thinking (working with a tabbarcontroller), do somehow I have to push this all the way back to my app delegate? Freeze the entire app until I get a location? That's my latest thoughts.

thanks for any tips, leads, snippets ... !!! I've been looking for days, no luck at all.

thanks!!!!

+1  A: 

You definitely don't want to "freeze" the app, and you definitely want to do as little work in your app delegate's applicationDidFinishLaunching: method as possible. What I might recommend:

  • Have two views: one is the "real" view with the map, (presumably) controlled by some view controller. The other is just a simple "waiting" view with a message to the user and a UIActivityIndicatorView, or something like that.
  • When your app launches, load and display the waiting view in your app's window, and kick off the location manager to find the user's current location.
  • When you've got enough location information, load the real view, add it to the window, and remove the waiting view. (Maybe with a nice cross-fade animation or something.)

You could also add both views, and just flip their hidden properties at the right time. But the point is to give the user something to look at, while not trying to fight the inherently asynchronous nature of Core Location.

Sixten Otto
hi, thanks for the quick reply. I think where I'm stuck is after I get a location from:(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocationHow do I feed it back to another method? So I can access it? I'm a semi-newbe here. thanks! I understand the delegate grabs it, but then what? I want to use that lat/lng value in another method.
ed potter
OK, I've gone back to square one. Using a plist setup for my locations. Makes more sense. Will tackle round 2 finding locations within my defined region (1 mile, 2 miles, etc). More to follow. Objective-C, yipes, what an adventure. :-)
ed potter
Well, the basic answer is: you need to have (to have a way to get) a reference from whatever is implementing the delegate protocol to whatever object needs the information. This is trivial, of course, if they're the same object, and more complicated if they're not. I'd suggest maybe starting another question to ask about the architecture of your app.
Sixten Otto