iOS,CoreLocation-应用加载时获取用户位置 [英] iOS, CoreLocation - Get users location when the app loads
问题描述
我正在尝试让我的应用程序在用户加载应用程序后立即获取其当前位置的经度和纬度。从这里我可以判断它们是否与某个点相距一定距离,并基于此调用不同的函数。
I am trying to get my app to get the longitude and latitude of the users current position as soon as they load up the app. From here I can tell if they are a certain distance from a point, and call different functions based on this.
我可以从viewDidLoad使其正常工作,但是我不想让该视图每次加载时都继续执行此操作。我该如何(如果可能)从应用程序委托didFinishLaunchingWithOptions方法中调用此方法?
I can get it to work fine from viewDidLoad, but I don't want it to keep performing this every time said view is loaded. How would I (if possible) call this from the app delegates didFinishLaunchingWithOptions method?
推荐答案
我认为您正在寻找CLLocationManager,这是GPS实施。它没有UI并在后台运行,但是您没有从PList调用它,而是实现了一个类。查找代码的 LocateMe示例项目。
I think you're looking for CLLocationManager, which is the GPS implementation. It has no UI and runs in the background, but you don't invoke it from the PList, you implement a class. Find the "LocateMe" example project for the code.
这篇关于iOS,CoreLocation-应用加载时获取用户位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!