[英]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). 我想做的是:用户将为音乐投票,但只有在距固定位置(经纬度)2公里的情况下,用户才能投票。
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.