How to get Venues list Using FourSquare Api
i want to get the list of venues nearby the current location i found a method of forsquare Api
+(void)searchVenuesNearByLatitude:(NSString*)lat
开发者_如何学Go 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.
I after studying the Foursquare Api Documentation.
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.
}
For more Information about foursquare API go through this link
精彩评论