获取ios8中的当前位置

时间:2014-10-28 06:37:45

标签: map ios8

我正在使用代码获取用户的当前位置,它使用ios7但不使用ios 8,这是我的代码,请告诉我哪里出错:

{


 //Start location manager
    mLocationManager = [[CLLocationManager alloc] init];

    [mLocationManager setDelegate:self];
    //We actually fetch current location only once, next line almost pointless
   // [mLocationManager setDistanceFilter:100.0f]; // 100m
    //[mLocationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters]; // 100 m
    [mLocationManager setDesiredAccuracy:kCLLocationAccuracyBest]; // 100 m

}   

2 个答案:

答案 0 :(得分:0)

获取当前位置。它正在ios8中为我工作

_locationManager = [[CLLocationManager alloc]init]; // initializing locationManager

_locationManager.delegate = self; // we set the delegate of locationManager to self.
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[_locationManager startUpdatingLocation];// add this line to update location

答案 1 :(得分:0)

在iOS8上,您应该在开始CLLocationManager

之前要求授权
[self.locationManager requestWhenInUseAuthorization];

另外,您需要在NSLocationWhenInUseUsageDescription中设置Info.plit