Patrice
Patrice

Reputation: 183

MKMapView and CLLocationManager

I want to use a MKMapView to display the user current location using the default breathing blue pin and I want to record the user movement at the same time. Is there any way that I could use the GPS manager (not sure if this is a CLLocationManager) the MKMapView uses when we enabled it to show user location?

I know that I can create my own CLLocationManager. But this feels like adding an overhead to my application and I would like the map and my tracking to remain in sync.

I already explored the following ideas without success:

Does anyone has any idea how I can achieve this and still benefit from the blue pin or is my only solution to use a CLLocationManager and create my own pin?

Upvotes: 17

Views: 7854

Answers (1)

Giao
Giao

Reputation: 15136

CLLocationManager uses the same data across all of its instances. MKMapView uses CLLocationManager's data internally. That said the solution to do what you want to do is let MKMapView do its own thing with regards to showUserLocation:. At the same time, create an instance of CLLocationManager and its delegate.

The delegate messages will give you the GPS coordinate location of MKMapView's blue pin. Everything will be in sync with each other.

Upvotes: 18

Related Questions