Question

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?

Was it helpful?

Solution 3

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top