CLLocationManager Singleton - 这是要走的路吗?
我正在构建一个具有两个简单视图(在选项卡栏中)的应用程序。
- 第一个视图:它应该显示用户的位置(默认蓝点)并从服务器加载数据。
- 第二个视图:它应该显示用户的位置(我的带有注释和标注的自定义引脚)。用户可以点击标注并提交有关当前位置的数据。
我首先使用 MKMapView 的showsUserLocation。 然后我读到最好使用 CLLocationManager 单例实例,所以我大致遵循了这篇博客文章: http://jinru.wordpress.com/2010/08/15/singletons-in-objective-c-an-example-of-cllocationmanager/
现在这几乎有效,但我想知道这是否是正确的做事方法。
另外,我找不到显示默认蓝点而不是自定义引脚的方法。我读到我应该使用 MKMapView 的 showUserLocation,但这不会创建 CLLocationManager 的另一个实例吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提到的博客文章中创建 CLLocationManager 单例的方法看起来不错。至于将showsUserLocation与CLLocationManager结合使用,应该没问题。 Apple 设计的 Core Location 可供多个应用程序同时使用。我不会引起太多问题。
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.