简体   繁体   中英

restkit Mapping CLLocationCoordinate2D from response

I have some geolocation data, and I need to parse it to CLLocationCoordinate2D from object geo

"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.

You can't go direct to a CLLocationCoordinate2D because it's a struct, not a class.

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 .

Your problem is that your JSON provides the location as an array, not a dictionary...

As such, you will need a different solution. You could look at making a modification to RKCLLocationValueTransformer (and raising a pull request). 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). Then modify transformValue:toValue:ofClass:error: to check the configuration and make the appropriate mappings.

After you've done that the github page describes how to use the transformer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM