始终从CLLocationManager获取相同的坐标

时间:2013-02-24 10:11:42

标签: ios objective-c geolocation core-location

我想使用CLLocationManager获取按钮上每次点击的当前位置,但总是得到相同的坐标:(

- (void)GetCoord
{
    self.currentLocation = nil;

    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [self.locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
    self.currentLocation = newLocation;

    UIAlertView *alert = [[UIAlertView alloc] 
        initWithTitle:@"Megerősítés" 
        message:[NSString stringWithFormat:@"%f ::: %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude] 
        delegate:self 
        cancelButtonTitle:@"Nem" 
        otherButtonTitles:nil
    ];

    [alert show];
    [self.locationManager stopUpdatingLocation];
}

1 个答案:

答案 0 :(得分:0)

  -(void) updateLocation
    {
        [locationManager startUpdatingLocation];
    }



- (void)locationManager:(CLLocationManager *)manager
        didUpdateToLocation:(CLLocation *)newLocation 
               fromLocation:(CLLocation *)oldLocation
    {
        userLocation.latitude = newLocation.coordinate.latitude;
        userLocation.longitude = newLocation.coordinate.longitude;

        [locationManager stopUpdatingLocation];
        //Send any notification to your controller about the update location.
    }