I am using Contentful.com
as a content-backend for my iOS
app. I can not get their geo-point
return to work for me in my Swift
project.
The Contentful documentation says their API
returns "NSData
with CLLocationCoordinate2D struct
."
I am approaching this with NSValue
in my project, but I can not get it to work properly. Here's my code:
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
However, locationCoord.latitude
and locationCoord.longitude
return
wrong values (one of them always being 0.0
).
Can someone tell me what I am doing wrong here, and how to make this work properly? Thanks.