Ios 位置列表中的地名/城市名称
这是我的情况。(使用Swift 2.2) 我有一个坐标列表(Ios 位置列表中的地名/城市名称,ios,swift,cllocation,reverse-geocoding,Ios,Swift,Cllocation,Reverse Geocoding,这是我的情况。(使用Swift 2.2) 我有一个坐标列表(CLLocation)。我需要调用reversegeocodocation获取相应的地点/城市。如果我尝试在元素之间循环,可能会有一些调用失败,因为苹果建议在一秒钟内发送一个调用。所以我需要在每次通话之间增加一个延迟 有没有办法做到这一点?感谢您的帮助 (如果我们有多个具有相同lat的项,只要我们只调用一次api)此代码声明一组位置并逐个查找,请求之间至少间隔1秒: var locations = Set<CLLocati
CLLocation
)。我需要调用reversegeocodocation
获取相应的地点/城市。如果我尝试在元素之间循环,可能会有一些调用失败,因为苹果建议在一秒钟内发送一个调用。所以我需要在每次通话之间增加一个延迟
有没有办法做到这一点?感谢您的帮助
(如果我们有多个具有相同lat的项,只要我们只调用一次api)此代码声明一组位置并逐个查找,请求之间至少间隔1秒:
var locations = Set<CLLocation>()
func reverseGeocodeLocation() {
guard let location = locations.popFirst() else {
geocodingDone()
return
}
CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
//Do stuff here
//Dispatch the next request in 1 second
_ = Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
self.reverseGeocodeLocation()
}
}
}
func geocodingDone() {
//Put your finish logic in here
}
var locations=Set()
func reversegeocodocation(){
guard let location=locations.popFirst()else{
geocodingDone()
返回
}
CLGeocoder().reverseGeocodeLocation(位置){placemarks,中有错误
//在这里做事
//在1秒内发送下一个请求
_=Timer.scheduledTimer(withTimeInterval:1,repeats:false){in
self.reversegeocodocation()
}
}
}
func geocodingDone(){
//把你的结束逻辑放在这里
}
仅供参考,计时器使用了块语法,但这仅适用于iOS 10。如果您使用的是iOS 9或更早版本,只需使用选择器版本,其工作方式与此相同。此代码声明一组位置并逐个查找,请求之间至少间隔1秒:
var locations = Set<CLLocation>()
func reverseGeocodeLocation() {
guard let location = locations.popFirst() else {
geocodingDone()
return
}
CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
//Do stuff here
//Dispatch the next request in 1 second
_ = Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
self.reverseGeocodeLocation()
}
}
}
func geocodingDone() {
//Put your finish logic in here
}
var locations=Set()
func reversegeocodocation(){
guard let location=locations.popFirst()else{
geocodingDone()
返回
}
CLGeocoder().reverseGeocodeLocation(位置){placemarks,中有错误
//在这里做事
//在1秒内发送下一个请求
_=Timer.scheduledTimer(withTimeInterval:1,repeats:false){in
self.reversegeocodocation()
}
}
}
func geocodingDone(){
//把你的结束逻辑放在这里
}
仅供参考,计时器使用了块语法,但这仅适用于iOS 10。如果您使用的是iOS 9或更早版本,只需使用选择器版本,其工作方式相同。部分相关-坐标列表来自何处?请确保缓存结果,以避免对过去获得的结果进行网络调用。@rmaddy是的,如果有多个项具有相同的lat,那么我们只调用一次api。该列表来自照片库。(我们将细节保存在DB中并使用这些项目)部分相关-坐标列表来自哪里?请确保缓存结果,以避免对过去获得的结果进行网络调用。@rmaddy是的,如果有多个项具有相同的lat,那么我们只调用一次api。该列表来自照片库。(我们将详细信息保存在DB中并使用这些项目)