Как я отбрасываю контакт с MapKit?

Я хотел бы позволить пользователю моего приложения выбирать местоположение в карте. Собственная карта имеет "функцию" контакта отбрасывания, где можно определить местоположение чего-то путем отбрасывания контакта. Как я могу сделать это в MapKit?

18
задан rjgonzo 7 February 2012 в 03:23
поделиться

1 ответ

You need to create an object that implements the MKAnnotation protocol and then add that object to the MKMapView:

@interface AnnotationDelegate : NSObject <MKAnnotation> {
    CLLocationCoordinate2D coordinate;
    NSString * title;
    NSString * subtitle;
} 

Instantiate your delegate object and add it to the map:

AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] initWithCoordinate:coordinate andTitle:title andSubtitle:subt] autorelease];
[self._mapView addAnnotation:annotationDelegate];

The map will access the coordinate property on your AnnotationDelegate to find out where to put the pin on the map.

If you want to customize your annotation view you will need to implement the MKMapViewDelegate viewForAnnotation method on your Map View Controller:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation

If you would like to implement the pin drag functionality you can read about handling annotation touch events in the Apple OS Reference Library.

You can also check out this article on drag drop with mapkit which refers to a working sample library on GitHub. You can get the coordinates of the dragged annotation by checking the _coordinates member on the DDAnnotation object.

27
ответ дан 30 November 2019 в 06:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: