gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:54:57 25 4
gpt4 key购买 nike

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

 -(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com