Created
October 28, 2012 02:43
-
-
Save Morse-Code/3967246 to your computer and use it in GitHub Desktop.
Boilerplate MKMapView annotation view creation and update based on map region.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pragma mark - | |
# MapView Delegate methods | |
- (void)mapView:(MKMapView *)map regionDidChangeAnimated:(BOOL)animated | |
{ | |
NSArray *oldAnnotations = mapView.annotations; | |
[mapView removeAnnotations:oldAnnotations]; | |
NSArray *weatherItems = [weatherServer weatherItemsForMapRegion:mapView.region maximumCount:4]; | |
[mapView addAnnotations:weatherItems]; | |
} | |
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation | |
{ | |
static NSString *AnnotationViewID = @"annotationViewID"; | |
WeatherAnnotationView *annotationView = | |
(WeatherAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; | |
if (annotationView == nil) | |
{ | |
annotationView = [[[WeatherAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease]; | |
} | |
annotationView.annotation = annotation; | |
return annotationView; | |
} | |
# pragma mark - | |
# MKAnnotation protocol | |
@interface | |
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; | |
@end | |
@implementation | |
- (CLLocationCoordinate2D)coordinate | |
{ | |
coordinate.latitude = [self.latitude doubleValue]; | |
coordinate.longitude = [self.longitude doubleValue]; | |
return coordinate; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment