使用定位功能需要需要接入高德地圖定位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兩個字段,內(nèi)容就是權(quán)限申請時的描述。
初始化定位管理類
import AMapLocationKit
var locationManage:AMapLocationManager!
實(shí)現(xiàn)定位代理AMapLocationManagerDelegate
設(shè)置代理和開始定位
//初始化定位
func initLocation(){
locationManage=AMapLocationManager()
locationManage.delegate=self
Permission.location(access: .always).request {
//連續(xù)定位是否返回逆地理信息
self.locationManage.locatingWithReGeocode=true
self.locationManage.startUpdatingLocation()
}
}
Permission是使用的一個權(quán)限申請框架PermissionsKit,這里就不細(xì)講了,給出鏈接:PermissionsKit
實(shí)現(xiàn)代理方法
需要實(shí)現(xiàn)兩個代理方法:文章來源:http://www.zghlxwxcb.cn/news/detail-794700.html
//定位回調(diào)
func amapLocationManager(_ manager: AMapLocationManager!, didUpdate location: CLLocation!) {
let infoString = String(format: "回調(diào)時間:%@\n經(jīng) 度:%.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")
}
結(jié)果
文章來源地址http://www.zghlxwxcb.cn/news/detail-794700.html
注意,模擬器定位結(jié)果是不準(zhǔn)確的,我這個就是,定位還有別的問題,建議用真機(jī)測試(但是要錢)
到了這里,關(guān)于IOS-高德地圖連續(xù)定位-Swift的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!