Skip to content

Instantly share code, notes, and snippets.

@mousebird
Last active December 18, 2015 11:29
Show Gist options
  • Save mousebird/5775717 to your computer and use it in GitHub Desktop.
Save mousebird/5775717 to your computer and use it in GitHub Desktop.
- (void)globeViewController:(WhirlyGlobeViewController *)viewC didTapAt:(WGCoordinate)coord
{
// We need degrees for the query, even if we work in radians internally
float lat = coord.y * 180.0 / M_PI;
float lon = coord.x * 180.0 / M_PI;
// We want the geometry and a couple of attributes for just one feature under the point
NSString *account = @"mousebird";
NSString *admin0Table = @"table_10m_admin_0_map_subunits";
NSString *queryStr = [NSString stringWithFormat:
@"http://%@.cartodb.com/api/v2/sql?format=GeoJSON&q=\
SELECT sovereignt,adm0_a3,the_geom FROM %@ \
WHERE ST_Intersects(the_geom,ST_SetSRID(ST_Point(%f,%f),4326)) \
LIMIT 1",account,admin0Table,lon,lat];
// Kick off the request with AFNetworking. We can deal with the result in a block
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:[queryStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:
// We'll do this if we succeed
^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
// Convert to GeoJSON and add the country outline
[self addCountry:[MaplyVectorObject VectorObjectFromGeoJSONDictionary:(NSDictionary *) JSON]];
}
failure:
// And nothing if we fail
^(NSURLRequest *request, NSHTTPURLResponse *response,NSError *error, id JSON)
{
}
];
// Kick off the network request
[operation start];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment