[英]restkit Mapping CLLocationCoordinate2D from response
I have some geolocation data, and I need to parse it to CLLocationCoordinate2D
from object geo
我有一些地理位置数据,我需要将其从对象
geo
解析为CLLocationCoordinate2D
"geo": [
49.233083,
28.46821699999998]
I found some information on how this could work with RKCLLocationValueTransformer
, but I don't understand how to get this to work for my situation. 我找到了一些有关如何与
RKCLLocationValueTransformer
一起使用的RKCLLocationValueTransformer
,但是我不知道如何RKCLLocationValueTransformer
适合我的情况。
You can't go direct to a CLLocationCoordinate2D
because it's a struct, not a class. 您不能直接访问
CLLocationCoordinate2D
因为它是结构而不是类。
RKCLLocationValueTransformer
works in the same way as the value transformer for dates (which convert from NSString
to NSDate
instances) except that it converts from NSDictionary
to CLLocation
. RKCLLocationValueTransformer
工作方式与日期(从NSString
转换为NSDate
实例)的值转换器相同,不同之处在于它从NSDictionary
转换为CLLocation
。
Your problem is that your JSON provides the location as an array, not a dictionary... 您的问题是您的JSON以数组而不是字典的形式提供了位置。
As such, you will need a different solution. 因此,您将需要其他解决方案。 You could look at making a modification to
RKCLLocationValueTransformer
(and raising a pull request). 您可以查看对
RKCLLocationValueTransformer
的修改(并提出拉取请求)。 Your modification would add a different creation method (perhaps locationValueTransformerForArrayRepresentation:
, which takes an enum parameter describing if the latitude or longitude comes first in the array). 您所做的修改将添加一个不同的创建方法(也许
locationValueTransformerForArrayRepresentation:
:,该方法采用一个枚举参数来描述纬度或经度在数组中排在首位)。 Then modify transformValue:toValue:ofClass:error:
to check the configuration and make the appropriate mappings. 然后修改
transformValue:toValue:ofClass:error:
以检查配置并进行适当的映射。
After you've done that the github page describes how to use the transformer. 完成后,github页面将介绍如何使用转换器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.