IOS-高德地图连续定位-Swift

使用定位功能需要需要接入高德地图定位Api:

pod 'AMapLocation'

配置Info

在info中新建一个名为Privacy - Location Temporary Usage Description Dictionary的字典,然后在这个字典下新建Privacy - Location When In Use Usage Description、Privacy - Location Always and When In Use Usage Description两个字段,内容就是权限申请时的描述。
在这里插入图片描述
IOS-高德地图连续定位-Swift_第1张图片

初始化定位管理类

import AMapLocationKit

var locationManage:AMapLocationManager!

实现定位代理AMapLocationManagerDelegate
在这里插入图片描述

设置代理和开始定位

    //初始化定位
    func initLocation(){
        locationManage=AMapLocationManager()
        locationManage.delegate=self
        
        Permission.location(access: .always).request {
            //连续定位是否返回逆地理信息
            self.locationManage.locatingWithReGeocode=true
            self.locationManage.startUpdatingLocation()
        }
    }

Permission是使用的一个权限申请框架PermissionsKit,这里就不细讲了,给出链接:PermissionsKit

实现代理方法

需要实现两个代理方法:

    //定位回调
    func amapLocationManager(_ manager: AMapLocationManager!, didUpdate location: CLLocation!) {
        let infoString = String(format: "回调时间:%@\n经 度:%.6f\n纬 度:%.6f\n精 度:%.3f米\n海 拔:%.3f米\n速 度:%.3f\n角 度:%.3f\n", location.timestamp.description, location.coordinate.longitude, location.coordinate.latitude, location.horizontalAccuracy, location.altitude, location.speed, location.course)
        print(infoString)
    }
    //不知道干嘛的,SDK要求的
    func amapLocationManager(_ manager: AMapLocationManager!, doRequireLocationAuth locationManager: CLLocationManager!) {
        print("location")
    }

结果

IOS-高德地图连续定位-Swift_第2张图片

注意,模拟器定位结果是不准确的,我这个就是,定位还有别的问题,建议用真机测试(但是要钱)

你可能感兴趣的:(IOS-Swift学习,ios,swift,开发语言,高德地图,定位)