gpt4 book ai didi

ios - 如何快速使用来自 reverseGeocodeLocation 的数据?

转载 作者:可可西里 更新时间:2023-11-01 02:16:51 26 4
gpt4 key购买 nike

编辑解决方案:因为我怀疑 reverseGeocodeLocation 是异步的所以我不得不使用

dispatch_async(
dispatch_get_main_queue(), {
self.newAddress = address
})

您还必须等到 newAddress 变量更新后才能使用它。有一些延迟,但这是典型的时间,如果是这样的话,大约是一秒钟。

原创:

我正在尝试使用 CLGeocoder().reverseGeocodeLocation 中的字符串在按下 map 上的注释时发送到另一个 View 。然而,处理程序存在于闭包中,其 Void in。我试过 String in 但这不符合协议(protocol)。

有什么方法可以使用闭包中的数据吗?

反向地理编码代码

 func getReversedGeocodeLocation(){
CLGeocoder().reverseGeocodeLocation(newMeetupLocation, completionHandler: {(placemarks, error) -> Void in


if error != nil {
print("Reverse geocoder failed with error" + error!.localizedDescription)
return
}

if placemarks != nil {
if placemarks!.count > 0 {
let pm = placemarks![0]
self.name = pm.name! + "-" + pm.thoroughfare!
}

}
else {
print("Problem with the data received from geocoder")
}
})
}

最佳答案

这是您要实现的目标吗?

    func getReversedGeocodeLocation(){
CLGeocoder().reverseGeocodeLocation(newMeetupLocation, completionHandler: {(placemarks, error) -> Void in


if error != nil {
print("Reverse geocoder failed with error" + error!.localizedDescription)
return
}

if placemarks != nil {
if placemarks!.count > 0 {
let pm = placemarks![0]
let myAddress = pm.name! + "-" + pm.thoroughfare!
// just pass the address along, ie
self.newAddressFromGeocode(myAddress)
}

}
else {
print("Problem with the data received from geocoder")
}
})
}

func newAddressFromGeocode(address:String) {
print(address)
// this is called from the completion handler
// do what you like here ie perform a segue and pass the string along
}

关于ios - 如何快速使用来自 reverseGeocodeLocation 的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37422235/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com