5

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.

user605957
  • 2,489
  • 6
  • 25
  • 33

3 Answers3

2

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.

Community
  • 1
  • 1
Robert Altman
  • 5,355
  • 5
  • 33
  • 51
0

If you are dealing with locations in Mainland China, I would recommend the MapKit location. It handles the calculation of the GPS offset (which is added by law for national security reasons) for you. More about this issue at https://en.wikipedia.org/wiki/Restrictions_on_geographic_data_in_China

Jinghan Wang
  • 1,139
  • 12
  • 21
0

I use CLLocationManager, precisely because of the centering on 1 infinite loop Dr. It also gives you more options, you can use startMonitoringSignificantChanges... etc.

Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • But the blue dot stays at 1 infinite loop dr... I cannot get it to go where CLLocationManager thinks the location is... – user605957 Jun 10 '11 at 18:20
  • it wont on the device. That is a simulator only issue, you can make a fake dot for debugging and set it as the same point as the maps center, it won't be exactly the same behavior, but close. – Grady Player Jun 10 '11 at 18:22
  • Thanks. SO bottom line is, if I use CLLocationManager, I should be good to go and on the real device the blue dot will coincide with where location received in didUpdateToLocation right? – user605957 Jun 10 '11 at 18:55
  • yeah the map view takes care of the blue dot, and you don't have any way to control it, on the simulator it just always stays in cupertino. – Grady Player Jun 10 '11 at 18:56
  • As of iOS 5, the simulator supports a number of location options, including changing the location. See http://stackoverflow.com/a/8175468/338468 for details. – Robert Altman May 08 '12 at 16:39