无法通过 Corelocation 找到位置
Posted
技术标签:
【中文标题】无法通过 Corelocation 找到位置【英文标题】:can't find location via 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]);
【问题讨论】:
【参考方案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
【讨论】:
以上是关于无法通过 Corelocation 找到位置的主要内容,如果未能解决你的问题,请参考以下文章
如果 CoreLocation 必须不断检索用户的位置,节省电池的提示?