【发布时间】:2014-11-18 10:45:59
【问题描述】:
我使用Contentful.com 作为我的iOS 应用程序的内容后端。我无法让他们的geo-point 在我的Swift 项目中为我工作。
Contentful 文档说他们的 API 返回“NSData 和 CLLocationCoordinate2D struct”。
我在我的项目中使用NSValue 来解决这个问题,但我无法让它正常工作。这是我的代码:
var locationCoord:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0,longitude: 0)
var locationData:NSData = entry.fields["location"] as NSData
var locationValue:NSValue = NSValue(bytes: locationData.bytes, objCType: "CLLocationCoordinate2D")
locationCoord = locationValue.MKCoordinateValue
但是,locationCoord.latitude 和 locationCoord.longitude return 值错误(其中一个始终是 0.0)。
谁能告诉我我在这里做错了什么,以及如何使它正常工作?谢谢。
【问题讨论】:
标签: swift ios8 nsvalue cllocationcoordinate2d