Sorry if this is a very noobish question, I just could not find any answer anywhere online. I am trying to encode GPS coordinates to JSON before sending with a Facebook Graph API. I think I am doing the right thing, but keep getting an error back from the API (which I am pretty sure relates to how I am creating this structure).
Is this the right way to encode GPS coordinates in Objective C?
NSMutableDictionary *params1 = [NSMutableDictionary dictionaryWithCapacity:3L];
NSString *latStr = [NSString stringWithFormat:@"%f", Coord.latitude];
NSString *lngStr = [NSString stringWithFormat:@"%f", Coord.longitude];
NSString *coordinatesString = [[NSString alloc] initWithFormat:@"%@,%@", latStr, lngStr];
[params1 setObject:dictionaryCoordinates forKey:@"coordinates"];
PS: Coord is a CLLocationCoordinate2D
This is what I am getting, which seems right to me:
coordinates = {
latitude = "33.24234";
longitude = "-120.34224";
};
Thanks!!!
2
Answers
I have no experience with the API, but I do not think, that coordinates are strings. But you send them as strings.
Use instances of
NSNumber
instead ofNSString. And you should have a view to
NSJSONParser`.If you need actual numbers then you can do:
The
@(...)
wraps the number as anNSNumber
.