gpt4 book ai didi

ios - 如何在 iOS 中按名称、位置搜索本地商家?

转载 作者:行者123 更新时间:2023-11-29 12:35:04 25 4
gpt4 key购买 nike

我正在做一个项目,在这个项目中我们展示本地商业搜索。我正在使用 YELP 搜索本地企业。根据 YELP Documentation我已经创建了查询。但它仅根据位置给出结果。

我正在尝试使用 Google Place API,但没有得到想要的结果。

我的 YELP 请求 - http://api.yelp.com/v2/search/?term=restaurant&location=nyc&limit=20&offset=1我的 Google Place API 请求 - https://maps.googleapis.com/maps/api/place/textsearch/json?query=hotels+in+nyc&sensor=true&key=AIzaSyCHwd5OgRXdeuTWV46SHdMLq2lXL20t22U

  1. 如何使用任何 YELP 或 Google Place API 获取公司名称和位置的结果?
  2. 使用 YELP 或 Google Place API 哪个更好?

最佳答案

1) 我使用了 Yelp API。特殊业务网址 - http://api.yelp.com/v2/business/用于全局搜索 - http://api.yelp.com/v2/search搜索后,您必须在 api 搜索 url 中正确传递数据。 NSStringWithFormat 中的 url 签名通知。并且不要忘记 OAuth key !我的要求:

-(void)searchBy:(NSString *)categoryFilter inLocationCity:(NSString *)aLocationCity {

NSString *urlString = [NSString stringWithFormat:@"%@?term=%@&location=%@",
YELP_SEARCH_URL,
categoryFilter,
aLocationCity];

NSURL *URL = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

OAConsumer *consumer = [[OAConsumer alloc] initWithKey:OAUTH_CONSUMER_KEY
secret:OAUTH_CONSUMER_SECRET];

OAToken *token = [[OAToken alloc] initWithKey:OAUTH_TOKEN
secret:OAUTH_TOKEN_SECRET];

id<OASignatureProviding, NSObject> provider = [[OAHMAC_SHA1SignatureProvider alloc] init];
NSString *realm = nil;

OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:URL
consumer:consumer
token:token
realm:realm
signatureProvider:provider];

[request prepare];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if (conn) {
self.urlRespondData = [NSMutableData data];
}

同时添加方法 NSURLConnectionDelegate:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

[self.urlRespondData setLength:0];

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d {
[self.urlRespondData appendData:d];

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

NSError *e = nil;
NSDictionary *resultResponseDict = [NSJSONSerialization JSONObjectWithData:self.urlRespondData
options:NSJSONReadingMutableContainers
error:&e];
if (self.resultArray && [self.resultArray count] > 0){

[self.resultArray removeAllObjects];
}

if (!self.resultArray) {
self.resultArray = [[NSMutableArray alloc] init];
}
DLog(@"YELP response %@", resultResponseDict);

if (resultResponseDict && [resultResponseDict count] > 0) {

if ([resultResponseDict objectForKey:@"businesses"] &&
[[resultResponseDict objectForKey:@"businesses"] count] > 0) {

for (NSDictionary *venueDict in [resultResponseDict objectForKey:@"businesses"]) {

Venue *venueObj = [[Venue alloc] initWithDict:venueDict];
[self.resultArray addObject:venueObj];
}
}
}

[self.delegate loadResultWithDataArray:self.resultArray];

关于ios - 如何在 iOS 中按名称、位置搜索本地商家?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26601838/

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