5

I implemented search bar in iOS application. I want to get the same (partial result) search hints as Apple Maps application. I tried to find out how apple implemented it but I was not successful on google or here on stackoverflow.

It doesn't matter what is displayed exactly in my UITableView *searchHintTableView. I just don't get correct number of search hints. I am using my application and Apple Maps application on same device and on the same 3G wifi network(3G SIM router).

What everything I tried:

  • I tried to specify region with radius.
  • To cancel geocode from previous request.

in method:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;

i have following piece of code:

    ...
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    NSString *location = [NSString stringWithFormat:@"%@", searchText];


//    CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coord
//                                                               radius:100000000 identifier:@"Hint Region"];

//    [geocoder cancelGeocode];
    [geocoder geocodeAddressString:location
                 completionHandler:^(NSArray *placemarks, NSError *error) {
                     if (error != nil) {
                         DDLogCVerbose(@"Error %@", [error description]);
                         [searchHintArray removeAllObjects];
                         [searchHintTableView reloadData];
                         return;
                     }
                     DDLogCVerbose(@"CLGeocoder >> %@", [placemarks description]);
                     //to get rid of unwanted results when searchText is inadequate
                     //even when previous partial results are not removed I don't get that many results as Apple Maps application.
                     [searchHintArray removeAllObjects]; 
                     [placemarks enumerateObjectsUsingBlock:^(CLPlacemark *placemark, NSUInteger idx, BOOL *stop) {
                         MKPlacemark *mkPlacemark = [[MKPlacemark alloc] initWithPlacemark:placemark];
                         [searchHintArray addObject:mkPlacemark];
                     }];
                     [searchHintTableView reloadData];
                 }
    ];
...

input parameters are following

  • searchText: Ess
  • latitude: 51.46
  • longitude: 7.01

Instead of 10 results(address related) from Apple Maps I get 2 at most(NSArray *placemarks).

With complete name of city "Essen" this code returns just 1 result. Apple maps 10 again.

Am I using the right API to display partial results as search hints? If not then how to do it correctly or which API should I use?

EDIT: As I was requested to explain why this is not duplicate I am editing this post. My Question was how to achieve same results as Apple Maps iOS app. I get accurate location when I enter bigger part of address or full address. I just don't get the same number of results when I enter small parts of address.

travdu
  • 331
  • 3
  • 9
  • Possible duplicate of [CLGeocoder geocoding is hopelessly inaccurate](http://stackoverflow.com/questions/11614721/clgeocoder-geocoding-is-hopelessly-inaccurate) – dvp.petrov May 04 '16 at 14:38
  • Take a look at this answer: http://stackoverflow.com/a/11848001/3883492 As far as I know, you cannot accomplished the result you are looking for with Apple MapKit API. – dvp.petrov May 04 '16 at 14:40
  • Here is the correct answer: Answered in 4 years in different thread. There should be badge "ancient monster slaughter" ;) https://stackoverflow.com/questions/43249382/mklocalsearch-doesnt-provide-the-same-results-as-search-in-native-apple-maps-ap?noredirect=1&lq=1 – travdu Aug 03 '20 at 13:39

0 Answers0