直接上代码
MKCoordinateSpan span = {0.01,0.01};
MKCoordinateRegion region = {self.selfLocation.coordinate ,span};
self.localSearchRequest = [[MKLocalSearchRequest alloc] init];
self.localSearchRequest.region = region;
self.localSearchRequest.naturalLanguageQuery = self.generalAddTextField.text;
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:self.localSearchRequest];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
if (error) {
NSLog(@"error info is:%@",error);
[[ZJRMBProgressHubTool shareHubTool] showAndHideHubWithString:@"网络错误,请检查您的连接" view:self.mapView];
}else{
for (MKMapItem *mapItem in response.mapItems) {
NSLog(@"========%@", mapItem);
CLLocation *location = mapItem.placemark.location;
[self updateMapView:location];
self.generalAddTextField.text = mapItem.name;
return ;
}
[[ZJRMBProgressHubTool shareHubTool] showAndHideHubWithString:@"没找到相应位置" view:self.mapView];
}
}];