是否可以使用MKLocalSearch查找附近的所有商家? [英] Is it possible to use MKLocalSearch to find all nearby businesses?

查看:1031
本文介绍了是否可以使用MKLocalSearch查找附近的所有商家?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了避免foursquare或其他本地搜索提供商的API限制,我想使用iOS 6.1中的MKLocalSearch。以下代码:

In order to avoid the API limits of foursquare or one of the other local search providers, I would like to use MKLocalSearch from iOS 6.1. The following code:

MKLocalSearchRequest *localSearchRequest = [[MKLocalSearchRequest alloc] init];
MKCoordinateRegion localSearchRegion = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake([theLocationChange.latitude floatValue], [theLocationChange.longitude floatValue]), 500.0f, 500.0f);
localSearchRequest.naturalLanguageQuery = @"restaurants";
localSearchRequest.region = localSearchRegion;
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:localSearchRequest];

[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error)
{
    if (error)
    {
        NSLog([error localizedDescription]);
    }
    for (MKMapItem* mapItem in response.mapItems)
    {
        NSLog(@"mapitem name is: %@",mapItem.name);
    }

}];

将正确获取并显示指定位置附近的餐馆。如果我将 localSearchRequest.naturalLanguageQuery 更改为hotels,它将获取并显示酒店。这同样适用于医院,酒吧等。但是,如果我尝试空字符串,或,*或?对于 localSearchRequest.naturalLanguageQuery ,它不返回任何结果。

will correctly fetch and display restaurants near the specified location. If I change localSearchRequest.naturalLanguageQuery to "hotels", it will fetch and display hotels. The same applies for "hospitals", "bars", etc. If, however, I try an empty string, or " ", "*", or "?" for localSearchRequest.naturalLanguageQuery, it returns no results.

如果我使用foursquare API并向其发送位置,我可以轻松找回包含所有类型的本地商家的场地列表。有没有办法使用MKLocalSearch返回所有场地或本地商家?

If I use the foursquare API and send it a location, I can easily get back a list of venues that includes local businesses of all types. Is there a way to use MKLocalSearch to return all venues or local businesses?

推荐答案

Apple文档说localSearchRequest.naturalLanguageQuery被认为是自然语言查询,这意味着,您可以键入任何内容并获取相关结果到您的查询。但Apples Maps数据库可能无法按预期返回值。

Apple documentation says that localSearchRequest.naturalLanguageQuery to be considered as natural Language query which means, you can type in anything and get the related results to your query. But Apples Maps database may not be returning the values as you expect.

这篇关于是否可以使用MKLocalSearch查找附近的所有商家?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆