注释引脚是可拖动的,但我不能将其拖放到目标位置。 问题是我怎么能得到目标位置的坐标,我放弃注释引脚? 任何方法存在? 编辑1: 注释引脚的中心似乎从来没有改变,我放弃任何地方的引脚。 – (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if (newState == MKAnnotationViewDragStateEnding) { NSLog(@"x is %f", annotationView.center.x); NSLog(@"y is %f", annotationView.center.y); CGPoint dropPoint = CGPointMake(annotationView.center.x, annotationView.center.y); CLLocationCoordinate2D newCoordinate = [self.mapView convertPoint:dropPoint toCoordinateFromView:annotationView.superview]; [annotationView.annotation setCoordinate:newCoordinate]; } } 编辑2: Annotation.h @property (nonatomic,readwrite,assign) CLLocationCoordinate2D coordinate; Annotation.m – (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate { coordinate = newCoordinate; } […]
我已经准备好了注释,但是试图找出如何使用我的代码拖动它: -(IBAction) updateLocation:(id)sender{ MKCoordinateRegion newRegion; newRegion.center.latitude = mapView.userLocation.location.coordinate.latitude; newRegion.center.longitude = mapView.userLocation.location.coordinate.longitude; newRegion.span.latitudeDelta = 0.0004f; newRegion.span.longitudeDelta = 0.0004f; [mapView setRegion: newRegion animated: YES]; CLLocationCoordinate2D coordinate; coordinate.latitude = mapView.userLocation.location.coordinate.latitude; coordinate.longitude = mapView.userLocation.location.coordinate.longitude; MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; [annotation setCoordinate: coordinate]; [annotation setTitle: @"Your Car is parked here"]; [annotation setSubtitle: @"Come here for pepsi"]; [mapView addAnnotation: annotation]; […]