gpt4 book ai didi

objective-c++ - 如何使用 FourSquare Api 获取 field 列表

转载 作者:行者123 更新时间:2023-12-04 06:10:56 25 4
gpt4 key购买 nike

我想获取当前位置附近的 field 列表
我找到了一个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;

但我不知道如何使用这种方法。
任何帮助将是可观的。

最佳答案

我在研究了 Foursquare Api 文档之后。

我得到了获取附近当前位置的 field 列表的方法。不需要使用 Foursquare 图书馆的预建方法(如我在我的问题中所示。)
为此,我们需要发出一个 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

关于objective-c++ - 如何使用 FourSquare Api 获取 field 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7783027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com