2

I have an iOS app where Im loading a MKMapView as the app starts. I want to set the center of the "MKCoordinateRegion" to be the user latitude/longitude. However, the CLLocation Manager instance does not update the user location until after the MKMapView has loaded.

For now I am hard coding the map center coordinates into the app. But I was wondering if anyone can suggest a better way to handle this situation.

I can think of 2 approaches but Im not a fan of either of them:

1) Stall launching the MKMapView using an activityindicator 2) Launch the MKMapview with the hard coded location and then as soon as the user location is available animate the mapview region to center on that location

Any suggestions?

banditKing
  • 9,405
  • 28
  • 100
  • 157

3 Answers3

1

Store the last known lat/long when you go to background or when app is closed.
On start center map view to last known position.
As soon as location manager sends an updated location, update the map center.

AlexWien
  • 28,470
  • 6
  • 53
  • 83
1

Set the userTrackingMode property of the mapview to MKUserTrackingModeFollow. You don't need a location manager for this, mapView does it for you. When you later want to relocate the map, set the property to MKUserTrackingModeNone, and relocate your map.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
0

Do what Apple does. Start really far zoomed out, maybe put a message on screen "Scanning for location", then when the location information is available zoom in.

Craig
  • 8,093
  • 8
  • 42
  • 74
  • Can you give me an example of an app that uses this approach? Thanks – banditKing Feb 14 '13 at 20:04
  • Apple's map program does the zoomed-far-out thing. The Scanning for Location was my addition since you said you were suggesting an activity indicator and I think it's better to tell the user what activity you're indicating. – Craig Feb 14 '13 at 21:49
  • Ahh I see. OK I get it. Thanks. I like this approach. – banditKing Feb 14 '13 at 21:52