Search code examples
iosmapkitcore-location

iOS search api for Apple Maps


Is there a search API for Apple Maps? Like in Apple Maps, if you start typing an address, it filters the list with some possibilities. Is this available to developers? I saw that they added some MKLocalSearch in iOS 7, but I could not find anything that gives that capability.


Solution

  • MKLocalSearch with MKLocalSearchRequest is exactly what you are looking for. A basic search can be done as follows:

    MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
            request.naturalLanguageQuery = @"some address";
    
    MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request];
    [localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
               // do stuff with the response
            }];
    

    This should put you on the right path. Read the docs for MKLocalSearch, MKLocalSearchRequest, and MKLocalSearchResponse.