Advertisement
wkerswell

Pins

Oct 23rd, 2012
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////////////////////////////
  2. #pragma mark - Pin Display
  3. /////////////////////////////
  4.  
  5.  
  6. -(void)pins:(NSString *)name lat:(NSString *)lat lon:(NSString *)lon
  7. {
  8.     NSLog(@"%@",name);
  9.     NSLog(@"%@",lat);
  10.     NSLog(@"%@",lon);
  11.    
  12.     //cast string to float
  13.     CGFloat Lat = (CGFloat)[lat floatValue];
  14.     CGFloat Lon = (CGFloat)[lon floatValue];
  15.    
  16.     //Set coordinates of pin
  17.     CLLocationCoordinate2D coordinate;
  18.     coordinate.latitude = Lat;
  19.     coordinate.longitude = Lon;
  20.    
  21.     //Create Pin
  22.     MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
  23.     //set details
  24.     [annotation setCoordinate:coordinate];
  25.     [annotation setTitle:name];
  26.     //[annotation setSubtitle:@"Here is where we do all our work!"];
  27.    
  28.     // Add pin to map
  29.     [self.showMapView addAnnotation:annotation];
  30.    
  31.     //This will allow you to open up safari when the button is pressed:
  32.     //[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"URL goes here"]];
  33. }
  34.  
  35. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
  36.     //create annotation
  37.     MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
  38.     if (!pinView) {
  39.         pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
  40.         pinView.pinColor = MKPinAnnotationColorRed;
  41.         pinView.animatesDrop = YES;
  42.         pinView.canShowCallout = YES;
  43.        
  44.         //details button
  45.         UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  46.         //if I want a method run on press
  47.         //[rightButton addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
  48.         pinView.rightCalloutAccessoryView = rightButton;
  49.        
  50.        
  51.     } else {
  52.         pinView.annotation = annotation;
  53.     }
  54.     return pinView;
  55. }
  56.  
  57.  
  58. //IMPLEMENT THIS ONE (WHEN DISCLOSURE BUTTON IS PRESSED):
  59. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
  60.     //create and annotation
  61.     MKPointAnnotation *annotation = view.annotation;
  62.     //get the title of the button press
  63.     NSString *temp = annotation.title;
  64.     NSLog(@"Pin button pressed: %@",temp);
  65.     [self performSegueWithIdentifier:@"showDetail" sender:self];
  66.    
  67. }
  68.  
  69.  
  70. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  71.     //if the segues is called showDetail prepare.
  72.     if ([[segue identifier] isEqualToString:@"showDetail"]) {
  73.        
  74.         //say where its going
  75.         SponsorDetailsViewController *detailViewController = [segue destinationViewController];
  76.        
  77.         //set the sponsor oject in the next view eq to the oject in the array that has the index of the row selected.
  78.         detailViewController.sponsorData = [self.ds objectAtIndex:0];
  79.        
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement