如何经常更新用户的GPS位置

问题描述 投票:-2回答:2

我正在开发一款我想要监控用户位置的游戏。并且它应该是如此频繁,就像游戏是关于击中我附近的用户,如果我击中他并且同一用户用户移出范围那么这将是我的错过。

我知道一种方法,我可以用时间间隔调用位置更新方法,但这对我来说似乎不太好,任何其他方式来实现这一点?

ios gps
2个回答
0
投票

您可以使用核心位置框架。委托方法如:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) {  // Check if the class assigning itself as the delegate conforms to our protocol.  If not, the message will go nowhere.  Not good.
        [self.delegate locationUpdate:newLocation];
    }
}

当用户更新位置时,将调用此方法。你也可以看看this教程。


0
投票

如果在核心位置设置distanceFilter,然后使用startUpdatingLocation启动位置跟踪,则只要移动设置的距离,就会获得更新。您想要做的事情可能很难取决于您想要“触摸”的“接近”程度,因为慢速移动的位置不是非常准确并且需要时间来更新。使用不到10米的触摸可能很困难。

© www.soinside.com 2019 - 2024. All rights reserved.