2015-10-09 29 views
-1

我用corelocation检测经度和纬度URL使用,但日志已打印0.00000两个不能通过Corelocation

找到位置,这是我的代码

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]) { 
} 
+0

谢谢,但我使用Objective-C不要迅速 –

1

您是否在Info.plist中添加了NSLocationWhenInUseUsageDescription?如果没有,然后添加此属性,并将其类型作为字符串和value = requestWhenInUseAuthorization