How to make a GET request with latitude and longitude paired a structure using AFNetworking?

80 views Asked by At

How to make a GET request with latitude and longitude paired a structure using AFNetworking?

GET graph.facebook.com
  /search?
    q=coffee&
    type=place&
    center=37.0,121.0&
    distance=10

The parameter center is a coordinate with latitude & longitude. How to do that using AFNetworking?

1

There are 1 answers

0
J.C. Chaparro On

You should add it to your parameters dictionary as a formatted string, something like this:

double lat=37.0;//your latitude
double lon=121.0;//your longitude
NSString *latLon = [NSString stringWithFormat:@"%f,%f", lat, lon];
NSDictionary *params = @[@"1":@"coffee", @"type":@"place"
    , @"center":latLon, @"distance":@"10"];    
NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"graph.facebook.com/"]];

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[client getPath:@"search"
     parameters:params
        success:^(AFHTTPRequestOperation *operation, id responseObject) {
            //Do something
        }
        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            //Do something
        }
 ];

This is just an example, as your architecture may already have a session manager, or an http client. Just enter the 'center' parameter as an NSString created from the latitude and longitude values you need.