![ios – Swift中的反向地理编码位置[已关闭],第1张 ios – Swift中的反向地理编码位置[已关闭],第1张](/aiimages/ios+%E2%80%93+Swift%E4%B8%AD%E7%9A%84%E5%8F%8D%E5%90%91%E5%9C%B0%E7%90%86%E7%BC%96%E7%A0%81%E4%BD%8D%E7%BD%AE%5B%E5%B7%B2%E5%85%B3%E9%97%AD%5D.png)
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函数中的致命错误.我把这个格式弄糟了吗?
解决方法 你永远不会反转地理编码的位置,但你通过manager.location.看到:
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中的反向地理编码位置[已关闭]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)