MKLocalSearch returning results outside of region

2.8k views Asked by At

I'm using Apple Maps to get a list of addresses in the local area. However, it seems to be returning results from all over the world, rather than the map region I am specifying.

I am using the following code, and have checked the region to make sure it is 'broadly' the whole of London (see attachment) for mapView with the same parameters. However in my results I sometimes have locations in Germany, USA or South America.

Anyone can see what I'm doing wrong?

MKLocalSearchRequest* request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = searchTerm;

CLLocationCoordinate2D cornerCoordinate = CLLocationCoordinate2DMake(51.5007282, -0.1246263);
request.region = MKCoordinateRegionMakeWithDistance(cornerCoordinate, 50000, 50000);

MKLocalSearch* search = [[MKLocalSearch alloc] initWithRequest:request];
[search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {

    //results come in here
}];

Map region: enter image description here

2

There are 2 answers

1
Mehul Patel On

Try this solution. Here I think issue is because of the region you specified.

MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = searchTerm;
MKCoordinateSpan span = MKCoordinateSpanMake(.1, .1);

CLLocationCoordinate2D cornerCoordinate = CLLocationCoordinate2DMake(51.5007282, -0.1246263);
request.region = MKCoordinateRegionMake(cornerCoordinate, span);
MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];


[search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
}];
0
zvonicek On

According to the documentation:

Specifying a region does not guarantee that the results will all be inside the region. It is merely a hint to the search engine.

It's bummer, but there's unfortunately no way to limit the results just to the provided region.

You may consider use a Google Places API for that: https://developers.google.com/places/webservice/autocomplete