dgee4
dgee4

Reputation: 381

Get MKLocalSearch to only return places

I have looked at the documentation and can't find a way to use MKLocalSearch to only return areas. For example I want the search to search world wide for cities, towns, villages & counties but not return any businesses or hotels etc. Is that possible?

Thanks

D

Upvotes: 1

Views: 2137

Answers (2)

user2931321
user2931321

Reputation: 476

based on your requirement change the key parameter for addressDictionary.

      for(MKMapItem *mapItem in response.mapItems)
    {
        NSLog(@"%@",mapItem.placemark.addressDictionary[@"Street"]);
}

Upvotes: 0

Sreejith Bhatt
Sreejith Bhatt

Reputation: 589

I think you can use predicate like this:

NSPredicate *noBusiness = [NSPredicate predicateWithFormat:@"business.uID == 0"];
NSMutableArray *itemsWithoutBusinesses = [response.mapItems mutableCopy];
[itemsWithoutBusinesses filterUsingPredicate:noBusiness]; 

Example local search code is also adding, which will solve your problem.

-(void)issueLocalSearchLookup:(NSString *)searchString {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.location.coordinate, 30000, 30000);
self.localSearchRequest = [[MKLocalSearchRequest alloc] init];
self.localSearchRequest.region = region;
self.localSearchRequest.naturalLanguageQuery = searchString;
self.localSearch = [[MKLocalSearch alloc] initWithRequest:self.localSearchRequest];

[self.localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
    if(error){
        NSLog(@"LocalSearch failed with error: %@", error);
        return;
    } else {
        for(MKMapItem *mapItem in response.mapItems){
            [self.data addObject:mapItem];
        }
        [self.searchDisplayController.searchResultsTableView reloadData];
    }
}];

}

Upvotes: 2

Related Questions