gpt4 book ai didi

ios - 无法将来自 geoCoder 的所有注释放在 map 上

转载 作者:行者123 更新时间:2023-11-29 01:58:06 27 4
gpt4 key购买 nike

-(void)showLocalRestaurantsWithDishRated:(MKUserLocation *)userLocation {

CLGeocoder *geoCoder = [[CLGeocoder alloc] init];

[[RestaurantController sharedInstance] getRestaurantsFromParse:^(NSMutableArray *restaurants) {
NSLog(@"%@",restaurants);

for (Restaurant *restaurant in restaurants) {
NSLog(@"%@", restaurant.address);
[geoCoder geocodeAddressString:restaurant.address completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"%@",placemarks);


for (MKPlacemark *placemark in placemarks) {


MKPlacemark *newPlaceMark = [[MKPlacemark alloc] initWithPlacemark:placemark];
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = newPlaceMark.coordinate;
point.title = restaurant.restaurantName;
point.subtitle = restaurant.address;


CLLocationCoordinate2D location = CLLocationCoordinate2DMake(placemark.location.coordinate.latitude, placemark.location.coordinate.longitude);


MKCoordinateRegion region = self.mapView.region;
region.span.latitudeDelta = 0.01;
region.span.longitudeDelta = 0.01;
region.center = location;


[self.mapView setRegion:region animated:YES];
[self.mapView addAnnotation:point];

}


}];
}
}];

restaurant.address 中的地址是这些:

  • 2250 N University Pkwy Provo, UT 84604
  • 2045 W Center St Provo, UT 84601
  • 1200 N University Ave Provo, UT 84604
  • 80 W Center St Provo, UT 84601
  • 434 W Center St Provo, UT 84601

问题是只有第一个地址被添加到 map 中。

最佳答案

您需要重构您的代码。您想要首先创建一个包含要添加到 map 的所有位置的数组。完成后,调用 addAnnotations(带有“s”)添加所有注释。您还需要根据您所有位置的跨度来计算您的区域,以确保 map 显示您的所有位置。然后,在计算出跨越所有位置所需的区域后,仅调用一次 setRegion

关于ios - 无法将来自 geoCoder 的所有注释放在 map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30626500/

27 4 0