简体   繁体   English

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

[英]How to update user's gps location frequently

I'm developing a game in which I want to monitor user's location.我正在开发一个游戏,我想在其中监控用户的位置。 And it should be so frequent, like the game is all about hit the user near by me, if I hit him and at the same user user moves out of the range then this will be a miss for me.而且它应该如此频繁,就像游戏的全部内容是击中我附近的用户,如果我击中他并且用户移出范围,那么这对我来说将是一个失误。

I know one way that I can call location update method with a time interval but that not seems good to me, any other way to achieve this?我知道一种可以按时间间隔调用位置更新方法的方法,但这对我来说似乎不太好,还有其他方法可以实现吗?

You can use the core location framework for this .您可以为此使用核心位置框架。 The delegate method like :委托方法如:

- (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 method gets called when the user updates the location .当用户更新位置时调用此方法。 you can also have look at this tutorial.你也可以看看 这个教程。

If you set the distanceFilter on the core-location and and then start the location tracking with startUpdatingLocation you will get updates whenever you move the set distance.如果您在核心位置上设置 distanceFilter,然后使用 startUpdatingLocation 开始位置跟踪,您将在移动设置的距离时获得更新。 What you want do do might be difficult depending on how "close" you want the "touch" to be as the location in slow movement is not extremely accurate and can take time to update.您想要做的事情可能很困难,这取决于您希望“触摸”的“接近”程度,因为缓慢移动的位置不是非常准确并且可能需要时间来更新。 Using less than 10m as a touch might be difficult.使用小于 10m 的触摸可能会很困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM