位置管理器更新频率,iPhone

发布于 2024-12-04 14:30:56 字数 1521 浏览 0 评论 0原文

我有一个名为“myLocation”的 CLLocation 管理器。

myLocation = [[CLLocationManager alloc] init];
    myLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
    myLocation.distanceFilter = 10 ;
    myLocation.delegate=self;



    locationEnabledBool = [CLLocationManager locationServicesEnabled];



    if (locationEnabledBool ==NO || ( [CLLocationManager  authorizationStatus] == kCLAuthorizationStatusDenied)) {

    //  LocationText.text = @"Location Service Disabled ";
        UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" 
                                                        message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles:nil];
        [locationAlert show];
        [locationAlert release];

    }

        [myLocation startUpdatingLocation];

位置更新功能是

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{

NSLog(@"old location is %f, %f ", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
NSLog(@"new location is %f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude );
}

有没有办法找到位置管理器更新的频率,以及是否可以增加或减少?

I have a CLLocation manager called "myLocation".

myLocation = [[CLLocationManager alloc] init];
    myLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
    myLocation.distanceFilter = 10 ;
    myLocation.delegate=self;



    locationEnabledBool = [CLLocationManager locationServicesEnabled];



    if (locationEnabledBool ==NO || ( [CLLocationManager  authorizationStatus] == kCLAuthorizationStatusDenied)) {

    //  LocationText.text = @"Location Service Disabled ";
        UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" 
                                                        message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles:nil];
        [locationAlert show];
        [locationAlert release];

    }

        [myLocation startUpdatingLocation];

and location update function is

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{

NSLog(@"old location is %f, %f ", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
NSLog(@"new location is %f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude );
}

Is there a way to find frequency of location manager update, and If it can be increased or decreased?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难以启齿的温柔 2024-12-11 14:30:56

仅当您调用方法[locationManager startUpdatingLocation]时,您的位置更新才会开始。

您可以使用 NSTimer 控制更新频率。当您需要位置更新时,定期调用 startUpdatingLocation 方法,然后立即调用 stopUpdatingLocation 方法。下次您将仅按照您在 NSTimer 中设置的时间间隔获取位置更新。

Your location update starts only when you call the method [locationManager startUpdatingLocation].

You can control the frequency of the update using an NSTimer. Call the startUpdatingLocation method at regular intervals whenever you need a location update and then immediately call the stopUpdatingLocation method. The next time you will get a location update only at the interval you have set in the NSTimer.

海未深 2024-12-11 14:30:56

为了检测最轻微的移动,您需要设置

myLocation.distanceFilter = kCLDistanceFilterNone ; 

但是,请记住,让位置管理器为即使最轻微的移动生成更新也可能导致大量电池使用。

For detecting even the slightest of movements, you need to set

myLocation.distanceFilter = kCLDistanceFilterNone ; 

But, please keep in mind,letting location manager to generate updates for even the slightest of movements can end up in lot of battery usage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文