ios - 如何在 ios 中停止多次调用 didUpdateLocations() 方法

标签 ios iphone cllocationmanager cllocation

这是我的代码......

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
 {

    location_updated = [locations lastObject];
    NSLog(@"updated coordinate are %@",location_updated);
    latitude1 = location_updated.coordinate.latitude;
    longitude1 = location_updated.coordinate.longitude;

    self.lblLat.text = [NSString stringWithFormat:@"%f",latitude1];
    self.lblLon.text = [NSString stringWithFormat:@"%f",longitude1];

    NSString *str = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",latitude1,longitude1];
    url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    connection = [NSURLConnection connectionWithRequest:request delegate:self];
    if (connection)
    {
        webData1 = [[NSMutableData alloc]init];
    }
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake(latitude1,longitude1);
        marker.title = formattedAddress;
        marker.icon = [UIImage imageNamed:@"m2.png"];
        marker.map = mapView_;
        marker.draggable = YES;
 }

这个方法被多次调用,我不想要.....

最佳答案

在分配 LocationManager 对象时,您可以设置 LocationManagerdistanceFilter 属性。距离过滤器属性是一个 CLLocationDistance 值,可以将其设置为通知位置管理器移动的距离(以米为单位)。您可以按如下方式设置距离过滤器:

LocationManager *locationManger = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = 100.0; // Will notify the LocationManager every 100 meters
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

关于ios - 如何在 ios 中停止多次调用 didUpdateLocations() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22292835/

相关文章:

ios - Objective-C:如何禁用 UIScrollView 中的垂直滚动

iphone - Rails3 和 Devise 与 Iphone/Android/Wp7 应用程序一起工作

iphone - 默认的 iPhone 相机应用程序如何能够如此快速地保存照片?

ios - 获取用户位置不起作用?

ios - 当应用程序终止时,位置后台模式是否可以快速工作?

iOS 位置管理器在手机锁定约 10 分钟后停止

ios - UITableViewCell GestureReognizer 的性能问题

iphone - 将评论与 Facebook iOS SDK (iPhone) 集成

ios - NSURLSession 在尝试向我们分配 IP 而不是 localhost 或 home 时失败

iphone - 类似于 Monotouch 的 NSDateFormatterMediumStyle 的日期格式?