-(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];
}
}];
}
}];
}
The addresses in restaurant.address
are these:
The problem is that only the first address is being added to map.
You need to restructure your code. You want to create an array of all the locations you want to add to the map first. Once you have that, then call addAnnotations
(with an "s") to add all the annotations. You will also need to calculate your region based on the span of ALL your location to ensure the map shows all your locations. Then call setRegion
only once AFTER you have calculated the region needed to span all your locations.