Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager Singleton - is this the way to go?

I'm building an app with two simple views (in a tabbar).

  • first view: it should show the user's location (default blue dot) and load data from a server.
  • second view: it should show the user's location (my custom pin with annotation and callout). the user can tap the callout and submit data about the current location.

I started by using MKMapView's showsUserLocation. Then I read that it's better to use a CLLocationManager singleton instance, so I followed this blog post roughly: http://jinru.wordpress.com/2010/08/15/singletons-in-objective-c-an-example-of-cllocationmanager/

Now this pretty much works, but I'm wondering if it's the correct way to do things.

Also, I couldn't find a way to show the default blue dot instead of a custom pin. I read that I should use MKMapView's showsUserLocation, but wouldn't that create another instance of CLLocationManager?

Thanks

like image 412
koichirose Avatar asked May 14 '11 20:05

koichirose


1 Answers

The method of creating a CLLocationManager singleton in the blog post you mentioned looks good. As for using showsUserLocation in combination with a CLLocationManager, it should be fine. Apple designed Core Location to be used by multiple applications at once. I won't cause too many issues.

like image 129
Patrick Tescher Avatar answered Oct 31 '22 15:10

Patrick Tescher