【问题标题】:can't find location via Corelocation无法通过 Corelocation 找到位置
【发布时间】:2015-10-09 07:45:09
【问题描述】:

我使用核心定位来检测要在 URL 中使用的纬度和经度,但日志在两者中都打印了 0.00000

这是我的代码

mapViewcontroller.m

#import <CoreLocation/CoreLocation.h>

@interface mapsViewController () <CLLocationManagerDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *mapsweb;
@property(weak,nonatomic) CLLocationManager *locationmanager;
@end

@implementation mapsViewController

-(NSString *)getlat{
    return [NSString stringWithFormat:@"%f",_locationmanager.location.coordinate.latitude];
}
-(NSString *)getlon{
    return [NSString stringWithFormat:@"%f",_locationmanager.location.coordinate.longitude];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _locationmanager = [[CLLocationManager alloc]init];
    _locationmanager.distanceFilter = kCLDistanceFilterNone;
    _locationmanager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    [_locationmanager startUpdatingLocation];

    NSString *t1 = @"http://mymaps.com/clat/";
    NSString *la = [self getlat];
    NSString *t2 = @"/clng/";
    NSString *lo = [self getlon];

    NSLog(@"latitude is %@",[self getlat]);
    NSLog(@"Longitude is %@",[self getlon]);

【问题讨论】:

    标签: ios objective-c core-location


    【解决方案1】:

    你没有使用 requestWhenInUseAuthorization 或 requestAlwaysAuthorization

    还请与以下代表核实-

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    
    }
    
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    }
    

    【讨论】:

    • 谢谢,但我用的是 Objective-C 不要 swift
    【解决方案2】:

    你是否在 Info.plist 中添加了 NSLocationWhenInUseUsageDescription?如果没有,则添加此属性并将其类型设置为 String 和 value = requestWhenInUseAuthorization

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2011-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多