- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
编辑解决方案:因为我怀疑 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/
我在使用 reverseGeocodeLocation 时遇到了一些奇怪的问题。这就是我所做的。 我从一个 view controller 推送到另一个。 View 出现后,我要求当前位置。在 did
关于抓取位置,iOS 模拟器经常不工作是否正常?每当我运行模拟器时,这个应用程序的项目都会在 50% 的时间内崩溃……但我似乎无法在代码本身中查明问题。如果问题确实出在代码本身,谁能帮我找到问题所在?
我的应用程序是基于地理位置的应用程序,tableview 中的每个条目都有条目的位置。我发现奇怪的是,当用户来自美国以外时,该位置是用他们的语言写的。例如,有一位来自越南的用户,地址是用越南语写的。我
这是我正在使用的代码。我不确定应该将哪些变量传递到完成处理程序中。我查看的所有其他帖子都说要传递“地标”和“错误”,但我遇到了警告和错误。 func locationManager(manager:
如果网络不可用,我在尝试对位置进行反向地理编码时看到奇怪的结果: 在 iOS 5.0.1 上看到 开启飞行模式 [geocoder reverseGeocodeLocation:whatever co
我有一个坐标数组,我使用 for 循环遍历这些坐标。我想在 map 上为每个位置放置注释,并将标注的副标题作为坐标的地址,通过使用 reverseGeocodeLocation 在 for 循环中,我
我从 Xcode 的方案中启用位置模拟检查 Allow Location Simulation 并从下拉列表中选择示例位置 - New York, NY, USA。 这是我从位置获取地点信息的代码。c
我在 iPhone 上使用 CLLocationManager 获取当前用户位置,然后使用 reverseGeocodeLocation 将位置转换为地址。 这工作正常,但结果以设备语言返回,我需要它
编辑解决方案:因为我怀疑 reverseGeocodeLocation 是异步的所以我不得不使用 dispatch_async( dispatch_get_main_queue
对于两个不同的坐标系,我无法从 CLGeocoder reverseGeocodeLocation 获得相同的结果。例如。 CLLocation *tempLocation = [[CLLocatio
我的 iPhone 应用程序应该根据用户的纬度和经度解析地址。reverseGeocodeLocation 工作正常,但结果是英文的。 有没有办法将结果本地化为其他语言? 无法在 apple 或其他任
这是我的代码和我尝试调用 reverseGeocodeLocation 的完整上下文: CLLocationCoordinate2D touchMapCoordinate = [self.mapVie
我正在使用 Corelocation 并更新基本的 long、lat 等以每秒查看尽可能多的 View ,这就是我想要的,但我现在引入了 reverseGeocodeLocation,我只希望它运行一
我想检测用户何时前往新国家/地区,因此打算将 startMonitoringSignificantLocationChanges: 与 reverseGeocodeLocation: 结合使用。 但是
我是 Swift 开发的新手。我刚刚将现有的工作代码转换为 swift2,同时从 6 更新 Xcode 7。 private func decodeLocation(array: [AnyOb
我模拟了一个外国位置,并使用了CLGeocoder reverseGeocodeLocation(_ location:, completionHandler:),但是我得到了一个错误- [Clien
我想编写一个函数来对位置进行反向地理编码并将结果字符串分配给一个变量。正在关注this发布我有这样的东西: extension CLLocation { func reverseGeocode
问题是completionHandler block 中的代码永远不会运行;我使用了断点,程序会在构建模式下跳过完成处理程序 block 下面是 PinALandPlaceMark 中使用的两个函数,
我正在开发具有反向地理编码功能的 iOS 应用程序。当我第一次调用该函数时,一切都很好。第二次调用后(使用完成调用的 Controller 的新实例)出现“Domain=kCLErrorDomain
我想做的是将 CLLocation 传递给函数 getPlacemarkFromLocation,然后函数通过 reverseGeocodeLocation 使用传递的 CLLocation 设置将返
我是一名优秀的程序员,十分优秀!