0

私がやろうとしていることは単純であるべきだと思いますが、それを検索する方法がわかりません!

私がやりたいことは: ユーザーは音楽に投票しますが、ユーザーは固定された場所 (緯度、経度) から 2 km 離れている場合にのみ投票できます。

これを実装するのに役立つリンクをいくつか提案できますか?!

乾杯。

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 に答える