我想获取当前位置附近的场地列表 我找到了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;
但我不知道如何使用这种方法。 任何帮助都会很明显。
答案 0 :(得分:3)
我在研究了Foursquare Api文档后。
我得到了场地列表附近当前位置的方式。不需要使用Foursquare Library的预建方法(正如我在我的问题中所示。) 为此我们需要发出一个HTTP请求,通过它我们得到JSON作为响应。 我已经编写了如下代码。
-(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.
}
For more Information about foursquare API go through this link