Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone app: Questions on interaction between CLLocationmanager and MKMapView (showing current user location)

In my iPhone app, I have the following logic:

  1. Start CLLocationManger (the user can supply accuracy and distance filters parameters to locationmanager, since best accuracy is not required in my case, 100-300 meters will do fine, and I'd like to save battery on this).

  2. After GPS fix is obtained by LocationManager (and only if this fix is obtained), I create and display the map. Both CLLocationManager and MKmapView are part of the same ViewController. To show the current location, I set mapView.showsUserLocation:YES, to display the blue dot. The locationManager I started still keeps working, getting GPS updates.

Apple documentation says this on MKMapView showsUserLocation:

Setting this property to YES causes the map view to use the Core Location framework to find the current location. As long as this property is YES, the map view continues to track the user’s location and update it periodically.

There's no word on which accuracy, or distance filter it is using for MKMapView's current location. It looks to me that at this point, I have both locationManager I started myself and mapView's own locationManager both updating locations!

Remember, I wanted to save some battery, by setting accuracy and distance filter? Are these parameters going to be respected by mapView's locationManager?

Also, are these two location managers going to be in sync one with another? I update the map to center it with new GPS coordinates my original locationManager gets. But I also want the blue dot to be visible in the center of the map. Will it be updated as well, each time, since I have mapView's showsUserLocation set to TRUE?

I would appreciate anyone who has clues about this.

like image 434
antonio Avatar asked Jun 04 '11 05:06

antonio


1 Answers

My understanding (based on what I see, not on documentation because I can't seem to find any that covers this) is that the showsUserLocation property causes the mapView to start a CLLocationManager instance using the highest accuracy settings (1m distance filter, best accuracy), and then update its blue circle annotation view as that location manager returns updates. It also updates a circular overlay based on the horizontal accuracy of the location updates. I believe this instance of CLLocationManager is separate from any you might start yourself, because I also run a CLLocationManager in parallel and don't see any interference from the map view's current location updates.

Therefore, if you don't want the MKMapView to run its own high accuracy location manager instance, then disable showsUserLocation and create and manually update your own current location MKAnnotationView based on your CLLocationManager's location updates. You can also zoom to the new updates as applicable.

I know this is essentially reinventing the wheel, but I believe it's the only way to get the functionality you want based on the tools Apple has provided. If anyone else knows otherwise, please chime in because I would also be interested.

like image 53
Kongress Avatar answered Oct 21 '22 06:10

Kongress