How can I limit user actions based on their proximity to a fixed point in iOS?
I 开发者_运维问答guess what I am trying to do should be simple, but don’t know how to search for it!
What I wanna do is: the user will vote for a music, but the user can only vote if he is 2km away from a fixed location (lat,lon).
Can you suggest some links that can help me implement this?!
Cheers.
Something like this...
@interface YourLocationViewController : UIViewController <CLLocationManagerDelegate>
CLLocationManager *locationManager;
...
/**
* Start tracking updates for location.
* Call this from viewLoad or something.
*/
-(void) trackUpdates {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
/* Pinpoint our location with the following accuracy:
*
* kCLLocationAccuracyBestForNavigation highest + sensor data
* kCLLocationAccuracyBest highest
* kCLLocationAccuracyNearestTenMeters 10 meters
* kCLLocationAccuracyHundredMeters 100 meters
* kCLLocationAccuracyKilometer 1000 meters
* kCLLocationAccuracyThreeKilometers 3000 meters
*/
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
/* Notify changes when device has moved x meters.
* Default value is kCLDistanceFilterNone: all movements are reported.
*/
self.locationManager.distanceFilter = 10.0f;
// update location
if ([CLLocationManager locationServicesEnabled]){
[self.locationManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CLLocationDistance meters = [newLocation distanceFromLocation:fixedPoint];
if (meters>2000){
// drink a shot
}
}
精彩评论