マップにドラッグ/ドロップ注釈を実装しようとしています。最初にピンはユーザーの現在の場所にドロップされますが[self.mapView setShowsUserLocation:YES];
、ピンをドラッグアンドドロップすると、しばらくして現在の場所に戻ります。
コードは次のとおりです。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize mapView;
- (void)viewDidLoad {
[super viewDidLoad];
mapView.delegate = self;
}
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation
{
//MKAnnotationView* annotationView = nil;
MKAnnotationView *annotationView = [mv dequeueReusableAnnotationViewWithIdentifier:@"PinAnnotationView"];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PinAnnotationView"];
annotationView.draggable = YES;
}
[self.locationManager stopUpdatingLocation];
return annotationView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
if(newState == MKAnnotationViewDragStateStarting) {
CLLocationCoordinate2D droppedFrom = annotationView.annotation.coordinate;
NSLog(@"dropped from %f, %f", droppedFrom.latitude , droppedFrom.longitude);
// annotationView.dragState = MKAnnotationViewDragStateDragging;
}
else if (newState == MKAnnotationViewDragStateEnding)
{
CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
annotationView.dragState = MKAnnotationViewDragStateNone;
}
else if (newState == MKAnnotationViewDragStateCanceling) {
// custom code when drag canceled...
// tell the annotation view that the drag is done
[annotationView setDragState:MKAnnotationViewDragStateNone animated:YES];
}
}
- (void)viewWillAppear:(BOOL)animated
{
[self.mapView setShowsUserLocation:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
私は何が欠けていますか?
前もって感謝します。