无法在地图上放置geoCoder中的所有注释

时间:2015-06-03 17:10:10

标签: ios mapkit clgeocoder

-(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

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

1 个答案:

答案 0 :(得分:1)

您需要重新构建代码。您希望首先创建要添加到地图的所有位置的数组。完成后,再调用addAnnotations(带“s”)添加所有注释。您还需要根据所有位置的跨度计算您的区域,以确保地图显示您的所有位置。然后,只有在计算了跨越所有位置所需的区域后,才拨打setRegion