关于高德定位不走代理方法的一些问题

1.在高德地图官网上注册 成功开发者

2.添加一个应用 注册一个appKey

3.用cocoa pod 中 写入 pod 'AMapLocation-NO-IDFA' #定位SDK 下载SDK

4需要在info.plist中追加 NSLocationWhenInUseUsageDescription 或NSLocationAlwaysUsageDescription 等字段,如下图

5.在appDelegate中 加入Key

    funcapplication(_application:UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey:Any]?) ->Bool{        AMapServices.shared().apiKey = "7c23cd5d3770XXX9528fe0cf6274d66"

return true

}

6.在你需要定位的页面写入:

        self.locationManager = AMapLocationManager.init()

        self.locationManager.delegate = self//实现代理

        self.locationManager.locatingWithReGeocode = true//连续定位是否返回逆地理信息,默认NO。

        self.locationManager.startUpdatingLocation()//开始连续定位。调用此方法会cancel掉所有的单次定位请求。

7.实现代理方法

//iOS10以上必须实现该方法,要不然无法调起下面的代理方法,即无法获取定位

    funcamapLocationManager(_manager:AMapLocationManager!, doRequireLocationAuth locationManager:CLLocationManager!) {

        locationManager.requestAlwaysAuthorization()

    }

 *  @brief 连续定位回调函数.注意:如果实现了本方法,则定位信息不会通过amapLocationManager:didUpdateLocation:方法回调。

 *  @param manager定位 AMapLocationManager 类。

 *  @param location 定位结果。

 *  @param reGeocode 逆地理信息。

 */

- (void)amapLocationManager:(AMapLocationManager *)managerdidUpdateLocation:(CLLocation *)locationreGeocode:(AMapLocationReGeocode *)reGeocode;

你可能感兴趣的:(关于高德定位不走代理方法的一些问题)