0

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

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

你能建议一些可以帮助我实现这一点的链接吗?!

干杯。

4

1 回答 1

3

像这样的东西...

@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
    }
}
于 2011-05-19T20:12:17.030 回答