如何根据 iOS 中与固定点的距离来限制用户操作?

发布于 2024-11-08 16:53:08 字数 126 浏览 4 评论 0原文

我想我想做的应该很简单,但不知道如何搜索它!

我想做的是:用户将为一首音乐投票,但用户只有在距离固定位置(纬度,经度)2公里时才能投票。

您能否建议一些可以帮助我实现此目的的链接?!

干杯。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放飞的风筝 2024-11-15 16:53:08

像这样的事

@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
    }
}

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文