gpt4 book ai didi

ios - 仅每 5 分钟获取一次 GPS 位置

转载 作者:行者123 更新时间:2023-11-28 18:12:01 25 4
gpt4 key购买 nike

在我的位置应用程序中实现了 didUpdateToLocation 方法。此方法每秒调用一次并提供位置数据。但我不需要每秒获取位置,我只需要每 5 分钟触发一次此方法。可以这样做吗?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//initialize location lisetener on Application startup
self.myLocationManager = [[CLLocationManager alloc]init];
self.myLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.myLocationManager.delegate = self;
[self.myLocationManager startUpdatingLocation];


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[INNOViewController alloc] initWithNibName:@"INNOViewController_iPhone" bundle:nil];
} else {
self.viewController = [[INNOViewController alloc] initWithNibName:@"INNOViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}


-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
/*
if(self.executingInBackground)
{
NSLog(@"Aplication running in background");
}
else
{
NSLog(@"Aplication NOT running in background");
}
*/


//NSLog(@"new location->%@ and old location -> %@",newLocation,oldLocation);

NSString *urlAsString = @"http://www.apple.com";

NSURL *url=[NSURL URLWithString:urlAsString];

NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url];

NSOperationQueue *queue = [[NSOperationQueue alloc]init];


[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

if ([data length] > 0 && error == nil) {
NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Downloaded html -> %@",html);
//NSLog(@"Downloaded successfully");
}
else if([data length] == 0 && error == nil)
{
NSLog(@"Nothing downloaded");
}
else
{
NSLog(@"Error occured -> %@",error);
}

}];
}

最佳答案

它被快速调用是因为您请求了 kCLLocationAccuracyBest。退后一点。它不是基于时间,而是基于增量距离。以这种精度,即使距离发生微小变化也会在接收良好的区域触发更新。使用不同的值。

同样,这些方法并不意味着要根据时间使用。它们旨在根据增量距离使用。

关于ios - 仅每 5 分钟获取一次 GPS 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16186996/

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