因此,我想说我试图搜索用户当前位置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对象。任何帮助,将不胜感激。感谢。