【发布时间】:2017-04-21 08:32:01
【问题描述】:
我正在尝试构建一个 iOS,我可以在其中每 x 秒更新一次我的位置并发送通知以更新 UI。 我得到了我的位置,但更新是随机的。任何想法如何添加间隔?
这是我的代码:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location = [locations lastObject];
[self sendNotification :@"long"
:[NSString stringWithFormat:@"%.8f",location.coordinate.longitude]];
[self sendNotification :@"lat"
:[NSString stringWithFormat:@"%.8f",location.coordinate.latitude]];
}
【问题讨论】:
-
当位置管理员可以在位置更改时通知您,为什么要每 x 秒更新一次。
-
即使它没有改变,我也需要它在一个区间内
-
这不是 CoreLocation 的工作方式。因此,您将不得不伪造它。将最新位置存储在变量中,并每隔 x 秒读取一次。
-
这段代码是在 appdelegate 还是 viewcontroller 中?
-
请参考这个你会得到一个想法stackoverflow.com/questions/6347503/…
标签: ios objective-c location