Advertisement
wkerswell

MapPinScale

Oct 12th, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ApplicationViewController.h"
  2.  
  3. @interface ApplicationViewController ()
  4.  
  5. @end
  6.  
  7. @implementation ApplicationViewController
  8. @synthesize mapView;
  9. @synthesize myLabel;
  10.  
  11.  
  12.  
  13.  
  14. - (void)viewDidLoad
  15. {
  16.    
  17.     [self goLocation];
  18.     [super viewDidLoad];
  19. }
  20.  
  21.  
  22. -(void) goLocation{
  23.     //Create region
  24.     mapView.mapType= MKMapTypeSatellite;
  25.     MKCoordinateRegion newRegion;
  26.     newRegion.center.latitude = 51.484864 ;
  27.     newRegion.center.longitude = -2.76013;
  28.     newRegion.span.latitudeDelta = 0.001149;
  29.     newRegion.span.longitudeDelta = 0.002411;
  30.     [self.mapView setRegion:newRegion animated:YES];
  31.    
  32.    
  33.     //Set coordinates of pin
  34.     CLLocationCoordinate2D coordinate;
  35.     coordinate.latitude = 51.484864;
  36.     coordinate.longitude = -2.76013;
  37.    
  38.     //Create Pin
  39.     MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
  40.     [annotation setCoordinate:coordinate];
  41.     [annotation setTitle:@"The Office"];
  42.     [annotation setSubtitle:@"Here is where we do all our work!"];
  43.    
  44.     // Add pin to map
  45.     [self.mapView addAnnotation:annotation];
  46.    
  47.     //This will allow you to open up safari when the button is pressed:
  48.     //[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"URL goes here"]];
  49. }
  50.  
  51. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
  52.    
  53.    
  54.     MKAnnotationView *pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"try"];
  55.     if (!pinView) {
  56.         pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"try"];
  57.         pinView.canShowCallout = YES;
  58.        
  59.         pinView.image = [UIImage imageNamed:@"1.png"];
  60.         pinView.canShowCallout = YES;
  61.        
  62.         UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  63.         pinView.rightCalloutAccessoryView = rightButton;
  64.     } else {
  65.         pinView.annotation = annotation;
  66.     }
  67.     return pinView;
  68. }
  69.  
  70.  
  71. //IMPLEMENT THIS ONE (WHEN DISCLOSURE BUTTON IS PRESSED):
  72. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
  73.     myLabel.text=@"hi";
  74. }
  75.  
  76.  
  77.  
  78. - (void)didReceiveMemoryWarning
  79. {
  80.     [super didReceiveMemoryWarning];
  81.     // Dispose of any resources that can be recreated.
  82. }
  83.  
  84. - (void)viewDidUnload {
  85.     [self setMapView:nil];
  86.     [self setMyLabel:nil];
  87.     [super viewDidUnload];
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement