ios8高德地图定位实效解决方法

在iOS8上currentLocation是空的,导致定位失败了。我们知道苹果在iOS8上对定位进行了大幅度优化,可以支持室内定位,常去地点统计,楼层等。

解决方法是:

1.工程的info.plist添加NSLocationWhenInUseDescription,NSLocationAlwaysUsageDescription字段,不同的字段对应的方法不同,只需加入字段,值可以不管

2.在AppDelegate.m中声明个CLLocationManager私有变量,代码如下:

添加

#import <CoreLocation/CLLocationManager.h>

@interface AppDelegate()<locationmanagerdelegate>

{

    UINavigationController *_navController;

    CLLocationManager      *_locationmanager;

}

 

@end

 

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    [UIApplication sharedApplication].idleTimerDisabled = TRUE;

     

    _locationmanager = [[CLLocationManager alloc] init];

    [_locationmanager requestAlwaysAuthorization];        //NSLocationAlwaysUsageDescription

    [_locationmanager requestWhenInUseAuthorization];     //NSLocationWhenInUseDescription

    _locationmanager.delegate = self;

}

这样在MAMapView的回调

-(void)mapView:(MAMapView*)mapView didUpdateUserLocation:(MAUserLocation*)userLocation updatingLocation:(BOOL)updatingLocation

就可以正常获取用户当前位置了,此时userLocation.location是有值的。



你可能感兴趣的:(ios8,高德地图实效问题)