gpt4 book ai didi

iphone - 从未调用过 didUpdateLocation 方法

转载 作者:可可西里 更新时间:2023-11-01 03:23:07 25 4
gpt4 key购买 nike

我正在 iphone sdk4.0 上制作一个应用程序。在其中没有调用从未调用过的更新位置方法。我在下面给出了我的代码。请帮忙。提前致谢。

-(id)init
{
[super init];

obj=[[UIApplication sharedApplication]delegate];

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
//locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];

return self;

}

-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%f",newLocation.coordinate.latitude);

NSLog(@"%f",newLocation.coordinate.longitude);

obj=[[UIApplication sharedApplication]delegate];

location=[[CLLocation alloc]initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
obj.lattitude1=[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];

obj.longitude1=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
//location=[[CLLocation alloc]initWithLatitude:39.9883 longitude:-75.262227];
}

最佳答案

此外,在 iOS8 中你必须有两个额外的东西:

  • 将 key 添加到您的 Info.plist 并向要求其启动的位置管理器请求授权。

    • NSLocationWhenInUseUsageDescription

    • NSLocationAlwaysUsageDescription

  • 您需要为相应的定位方法请求授权。

    • [self.locationManager requestWhenInUseAuthorization]

    • [self.locationManager requestAlwaysAuthorization]

代码示例:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];

来源:http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

关于iphone - 从未调用过 didUpdateLocation 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5374216/

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