简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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