如何使用FourSquare Api获取场地列表 [英] How to get Venues list Using FourSquare Api
问题描述
我想获取当前位置附近的场地列表 我找到了forsquare Api的方法
i want to get the list of venues nearby the current location i found a method of forsquare Api
+(void)searchVenuesNearByLatitude:(NSString*)lat
longitude:(NSString*)lon
accuracyLL:(NSString*)accuracyLL
altitude:(NSString*)altitude
accuracyAlt:(NSString*)accuracyAlt
query:(NSString*)query
limit:(NSString*)limit
intent:(NSString*)intent
callback:(Foursquare2Callback)callback;
但是我不知道如何使用这种方法. 任何帮助将是可观的.
But i don't know how to use this method. Any help would be appreciable.
推荐答案
我研究了Foursquare Api文档.
I after studying the Foursquare Api Documentation.
我有办法获取附近当前地点的场地列表.不需要使用Foursquare Library的pre-Built方法(正如我在我的问题"中所示). 为此,我们需要发出一个HTTP请求,通过该请求,我们得到JSON作为响应. 我已经编写了如下代码.
I got the way of getting the Venues List Nearby current location.No need to Use pre-Built method of Foursquare Library(as I have shown in My Question.) For This We need to make a HTTP request,By which we get JSON as response. I have written the Code As below.
-(void)getVenuesList{
NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc]init] autorelease];
[dateFormatter setDateFormat:@"YYYYMMdd"];
NSString *dateString = [dateFormatter stringFromDate:currDate];
//dateString it;s used for being UpTodate for API request
NSString* rediusMtr=@"2000";//distance under the comes
NSString *acess_Token=@"OAuth_Token ";
//acess_TokenOuth Token got from Foursqaure after registarting the App.
CGFloat latitude=245425435.564;//latitude & longitude coordinate
CGFloat longitude=245443435.564;
NSString *latitudeStr=[NSString stringWithFormat:@"%f,",latitude];
NSString *longitudeStr=[NSString stringWithFormat:@"%f",longitude];
NSMutableString*latitudeLongitudeString =[[NSMutableString alloc]initWithString:latitudeStr];
[latitudeLongitudeString appendString:longitudeStr];
NSString *query=@"airport";//Venuse to be searched.
NSString *resultLimit=@"50";//number of result to be returned.
NSString *URLString=[NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/search?ll=%@&query=%@&limit=%@&radius=%@&oauth_token=%@&v=%@",latitudeLongitudeString,query,resultLimit,rediusMtr,acess_Token,dateString];
URLString =[URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]];
//Perform request and get JSON back as a NSData object
NSError *error = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
if(error != nil) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Done"otherButtonTitles:nil] autorelease];
[alert show];
}
else {
NSString *jsonString = [[[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"%@",jsonString);
SBJSON *parser = [[[SBJSON alloc] init] autorelease];
NSDictionary *jsonResponse = (NSDictionary*)[parser objectWithString:jsonString error:nil];
NSDictionary *responseData = [[jsonResponse objectForKey:@"response"] objectForKey:@"venues"] ;
NSArray *resultsArray= [responseData valueForKey:@"name"] ;
NSArray*distanceArray=[[responseData valueForKey:@"location"] valueForKey:@"distance"];
//Now we can use above resultsArray,distanceArray data.
}
这篇关于如何使用FourSquare Api获取场地列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!