- (void)findCurrentLocation {
    self.isFirstUpdate = YES;
    [self.locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    if (self.isFirstUpdate) {
        self.isFirstUpdate = NO;
        return;
    }
    
    CLLocation *location = [locations lastObject];
    
    /*当定位成功后,如果horizontalAccuracy大于0,说明定位有效
     horizontalAccuracy,该位置的纬度和经度确定的圆的中心,并且这个值表示圆的半径。负值表示该位置的纬度和经度是无效的。
     */
    if (location.horizontalAccuracy > 0) {
        self.currentLocation = location;
        [self.locationManager stopUpdatingLocation];
    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章:

  • 2022-12-23
  • 2021-12-06
  • 2021-05-08
  • 2021-11-14
  • 2021-09-29
  • 2022-12-23
  • 2021-12-27
  • 2021-04-06
猜你喜欢
  • 2021-08-28
  • 2021-09-25
  • 2022-12-23
  • 2021-06-30
  • 2021-12-05
  • 2022-03-05
  • 2021-09-12
相关资源
相似解决方案