gpt4 book ai didi

xcode - 如何根据用户与 iOS 中固定点的接近程度来限制用户操作?

转载 作者:行者123 更新时间:2023-11-28 20:46:14 26 4
gpt4 key购买 nike

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

我想做的是:用户将为音乐投票,但用户只能在距离固定位置(纬度、经度)2 公里的情况下投票。

你能推荐一些可以帮助我实现这个的链接吗?!

干杯。

最佳答案

像这样的……

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

关于xcode - 如何根据用户与 iOS 中固定点的接近程度来限制用户操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6064043/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com