4

So let's say I'm trying to search for a query within 1 mile radius of the user's current location. Here's my search code so far:

- (void) performLocalSearch{
     MKLocalSearchRequest *searchRequest = [[MKLocalSearchRequest alloc] init];
     searchRequest.naturalLanguageQuery = _searchText;
     MKCoordinateRegion searchRegion;
     searchRegion.center.latitude = userLocation.coordinate.latitude;
     searchRegion.center.longitude = userLocation.coordinate.longitude;
     searchRegion.span.latitudeDelta = 0.0144927536231884;
     searchRegion.span.longitudeDelta = 0.0144927536231884;
     searchRequest.region = searchRegion;


     MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:searchRequest];

     [search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
          for (MKMapItem *item in response.mapItems) {
               MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
               annotation.title = item.name;
               annotation.coordinate = item.placemark.coordinate;

               [_map addAnnotation:annotation];
          }
      }
      ];
}

When I run the code on my device, pins show up on the map, but they are not within the specified radius. I also tried using MKCoordinateRegionMakeWithDistance to set the search region but I couldn't figure out how to cast the double radius value as a CLLocationDistance object. Any help would be appreciated. Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Doesn't answer your main question but regarding MKCoordinateRegionMakeWithDistance: `CLLocationDistance` is not an object. It is a primitive type and it is actually a double. See [Core Location Data Types](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CoreLocationDataTypesRef/Reference/reference.html#//apple_ref/doc/uid/TP40010238-CH2-SW11). It represents distance in meters. –  Jun 06 '14 at 02:39

0 Answers0