Allow tapping anywhere on an annotation callout without a callout accessory view

前端 未结 5 1571
情歌与酒
情歌与酒 2020-12-28 16:35

I have a map view that adds annotations more or less like this:

- (MKAnnotationView *)mapView:(MKMapView *)mapView
            viewForAnnotation:(id 

        
5条回答
  •  余生分开走
    2020-12-28 17:09

    - (void)mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
        Park *parkAnnotation = (Park *)[view annotation];
        switch ([control tag]) {
            case 0: // left button
            {
                NSURL *url = [NSURL URLWithString:parkAnnotation.link];
                [[UIApplication sharedApplication] openURL:url];
            }
                break;
    
            case 1: // right button
            {
                // build a maps url. This will launch the Maps app on the hardware, and the apple maps website in the simulator
                CLLocationCoordinate2D coordinate = self.locationManager.location.coordinate;
                NSString *url2 = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f",coordinate.latitude,coordinate.longitude,parkAnnotation.location.coordinate.latitude,parkAnnotation.location.coordinate.longitude];
    
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url2]];
            }
                break;
    
            default:
                NSLog(@"Should not be here in calloutAccessoryControlTapped, tag=%ld!",(long)[control tag]);
                break;
        }
    }
    

提交回复
热议问题