4

因此,假设我正在尝试在用户当前位置 1 英里半径范围内搜索查询。到目前为止,这是我的搜索代码:

- (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];
          }
      }
      ];
}

当我在我的设备上运行代码时,图钉会显示在地图上,但它们不在指定的半径内。我还尝试使用 MKCoordinateRegionMakeWithDistance 设置搜索区域,但我无法弄清楚如何将双半径值转换为 CLLocationDistance 对象。任何帮助,将不胜感激。谢谢。

4

0 回答 0