How do I drop a pin with MapKit?

前端 未结 4 1582
一向
一向 2020-12-24 02:56

I would like to allow the user of my app to pick a location in the map. The native map has a \"drop pin\" feature where you can locate something by dropping a pin. How can I

4条回答
  •  眼角桃花
    2020-12-24 03:34

    You might also need to set MapView Delegate.

    [mkMapView setDelegate:self];
    

    Then call its delegate, viewForAnnotation:

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
        MKPinAnnotationView *pinAnnotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
                                                                        reuseIdentifier:@"current"];
        pinAnnotationView.animatesDrop = YES;
        pinAnnotationView.pinColor = MKPinAnnotationColorRed;
        return pinAnnotationView;
    }
    

提交回复
热议问题