大佬教程收集整理的这篇文章主要介绍了ios – Swift中的反向地理编码位置[已关闭],大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
println(geopoint.longitudE) println(geopoint.latitudE) var manager : CLLOCATIOnManager! var longitude :CLLOCATIOndegrees = geopoint.longitude var latitude :CLLOCATIOndegrees = geopoint.latitude var LOCATIOn: CLLOCATIOnCoordinate2D = CLLOCATIOnCoordinate2DMake(latitude,longitudE) println(LOCATIOn) CLGeocoder().reverseGeocodeLOCATIOn(manager.LOCATIOn,completionHandler: {(placemarks,error) -> Void in println(manager.LOCATIOn) if error != nil { println("Reverse geocoder Failed with error" + error.localizedDescription) return } if placemarks.count > 0 { let pm = placemarks[0] as CLPlacemark println(pm.locality) } else { println("Problem with the data received from geocoder") }
在我得到的日志中
//-122.0312186 //37.33233141 //C.CLLOCATIOnCoordinate2D //Fatal error: unexpectedly found nil while unwrapping an Optional value
看来CLLOCATIOnCoordinate2DMake功能失败,这会导致reverseGeocodeLOCATIOn函数中的致命错误.我把这个格式弄糟了吗?
看到:
CLGeocoder().reverseGeocodeLOCATIOn(manager.LOCATIOn,…
我认为这是一个复制和粘贴错误,这是一个问题 – 代码本身看起来不错 – 几乎;)
工作代码
var longitude :CLLOCATIOndegrees = -122.0312186 var latitude :CLLOCATIOndegrees = 37.33233141 var LOCATIOn = CLLOCATIOn(latitude: latitude,longitude: longitudE) //changed!!! println(LOCATIOn) CLGeocoder().reverseGeocodeLOCATIOn(LOCATIOn,error) -> Void in println(LOCATIOn) if error != nil { println("Reverse geocoder Failed with error" + error.localizedDescription) return } if placemarks.count > 0 { let pm = placemarks[0] as! CLPlacemark println(pm.locality) } else { println("Problem with the data received from geocoder") } })
以上是大佬教程为你收集整理的ios – Swift中的反向地理编码位置[已关闭]全部内容,希望文章能够帮你解决ios – Swift中的反向地理编码位置[已关闭]所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。