Created
December 13, 2012 03:59
-
-
Save ChrisRisner/4273903 to your computer and use it in GitHub Desktop.
iOS Day 20
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
#import <MapKit/MapKit.h> | |
@interface MapAnnotation : NSObject <MKAnnotation>{ | |
CLLocationCoordinate2D _coordinate; | |
} | |
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate; | |
@end |
This file contains hidden or 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
#import "MapAnnotation.h" | |
@implementation MapAnnotation | |
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate { | |
self = [super init]; | |
if (self != nil) { | |
_coordinate = coordinate; | |
} | |
return self; | |
} | |
@end |
This file contains hidden or 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
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation { | |
if ([annotation isKindOfClass:[MKUserLocation class]]) { | |
return nil; | |
} | |
static NSString *AnnotationViewID = @"annotationViewID"; | |
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; | |
if (annotationView == nil) { | |
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; | |
} | |
annotationView.canShowCallout = YES; | |
annotationView.annotation = annotation; | |
return annotationView; | |
} |
This file contains hidden or 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
- (IBAction)tappedAdd:(id)sender { | |
CLLocationCoordinate2D mapPoint; | |
mapPoint.longitude = -122.132; | |
mapPoint.latitude = 47.624300; | |
MKPointAnnotation *anny = [[MKPointAnnotation alloc] init]; | |
anny.coordinate = mapPoint; | |
anny.title = @"Annotation description"; | |
anny.subtitle = @"Annotation subtitle"; | |
[self.mapView addAnnotation:anny]; | |
} |
This file contains hidden or 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
- (IBAction)tappedRemove:(id)sender { | |
for (id annotation in self.mapView.annotations) | |
if (![annotation isKindOfClass:[MKUserLocation class]]) { | |
[self.mapView removeAnnotation:annotation]; | |
} | |
} |
This file contains hidden or 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
#import <UIKit/UIKit.h> | |
#import <MapKit/MapKit.h> | |
#import "CoreLocationController.h" | |
@interface ViewController : UIViewController <CoreLocationControllerDelegate, MKMapViewDelegate> | |
@property (weak, nonatomic) IBOutlet UILabel *lblLongitude; | |
@property (weak, nonatomic) IBOutlet UILabel *lblLatitude; | |
@property (weak, nonatomic) IBOutlet MKMapView *mapView; | |
@property (nonatomic, retain) CoreLocationController *locationController; | |
- (IBAction)tappedAdd:(id)sender; | |
- (IBAction)tappedRemove:(id)sender; | |
@end |
This file contains hidden or 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
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
self.mapView.showsUserLocation = YES; | |
self.mapView.delegate = self; | |
self.locationController = [[CoreLocationController alloc] init]; | |
self.locationController.delegate = self; | |
[self.locationController.locationManager startUpdatingLocation]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment