Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager didUpdateToLocation versus MKMapView's didUpdateUserLocation

I get the user's location from both CLLocationManager and MKMapView. Which one should I use to set the Map's center coordinate?

Also, the two methods in the simulator differ in their answers. The CLLocationManager returns the correct location whereas the MKMapview's didUpdateUserLocation returns the Apple office in cupertino.

like image 792
user605957 Avatar asked Nov 04 '22 20:11

user605957


1 Answers

I would use the MapKit location when working with the map.

The map routines are intended for use while working with the map; while the CoreLocation routines are intended for use irrespective of the map. MapKit will report location changes that affect the map (didUpdateUserLocation is called if showUserLocation is YES or the tracking mode is MKUserTrackingModeFollowWithHeading). CoreLocation's services are capable of reporting changes while the application is in the background.

The bottom line is you should use the option which is appropriate for what you are doing. In my application, I use both services: MapKit when the map is displayed, and CoreLocation whenever the map is no displayed or the app is backgrounded.

Anecdotally, since the release of iOS 5, the simulator supports a number of location options; look on the Debug menu for the simulator application, I also described some of these options at https://stackoverflow.com/a/8175468/338468.

like image 188
Robert Altman Avatar answered Nov 09 '22 06:11

Robert Altman