Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////
- #pragma mark - Pin Display
- /////////////////////////////
- -(void)pins:(NSString *)name lat:(NSString *)lat lon:(NSString *)lon
- {
- NSLog(@"%@",name);
- NSLog(@"%@",lat);
- NSLog(@"%@",lon);
- //cast string to float
- CGFloat Lat = (CGFloat)[lat floatValue];
- CGFloat Lon = (CGFloat)[lon floatValue];
- //Set coordinates of pin
- CLLocationCoordinate2D coordinate;
- coordinate.latitude = Lat;
- coordinate.longitude = Lon;
- //Create Pin
- MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
- //set details
- [annotation setCoordinate:coordinate];
- [annotation setTitle:name];
- //[annotation setSubtitle:@"Here is where we do all our work!"];
- // Add pin to map
- [self.showMapView addAnnotation:annotation];
- //This will allow you to open up safari when the button is pressed:
- //[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"URL goes here"]];
- }
- - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
- //create annotation
- MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
- if (!pinView) {
- pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
- pinView.pinColor = MKPinAnnotationColorRed;
- pinView.animatesDrop = YES;
- pinView.canShowCallout = YES;
- //details button
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
- //if I want a method run on press
- //[rightButton addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
- pinView.rightCalloutAccessoryView = rightButton;
- } else {
- pinView.annotation = annotation;
- }
- return pinView;
- }
- //IMPLEMENT THIS ONE (WHEN DISCLOSURE BUTTON IS PRESSED):
- - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
- //create and annotation
- MKPointAnnotation *annotation = view.annotation;
- //get the title of the button press
- NSString *temp = annotation.title;
- NSLog(@"Pin button pressed: %@",temp);
- [self performSegueWithIdentifier:@"showDetail" sender:self];
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- //if the segues is called showDetail prepare.
- if ([[segue identifier] isEqualToString:@"showDetail"]) {
- //say where its going
- SponsorDetailsViewController *detailViewController = [segue destinationViewController];
- //set the sponsor oject in the next view eq to the oject in the array that has the index of the row selected.
- detailViewController.sponsorData = [self.ds objectAtIndex:0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement