带iOS的可拖动批注:标注信息更新
我对可拖动注释的标注信息有问题:我使用MKReverseGeocoder获取与注释位置对应的坐标的地址 但有一点我无法控制:每次删除可拖动注释时,都会显示标注信息。通常,MKReverseGeocoder在发生这种情况之前没有时间更新地址信息。因此,在这些常见情况下,注释标注显示与注释先前坐标相对应的地址信息 代码如下: 1) 删除批注时调用的委托方法:带iOS的可拖动批注:标注信息更新,ios,annotations,mapkit,draggable,Ios,Annotations,Mapkit,Draggable,我对可拖动注释的标注信息有问题:我使用MKReverseGeocoder获取与注释位置对应的坐标的地址 但有一点我无法控制:每次删除可拖动注释时,都会显示标注信息。通常,MKReverseGeocoder在发生这种情况之前没有时间更新地址信息。因此,在这些常见情况下,注释标注显示与注释先前坐标相对应的地址信息 代码如下: 1) 删除批注时调用的委托方法: - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState{
if (oldState == MKAnnotationViewDragStateDragging) {
MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:annotationView.annotation.coordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
while (reverseGeocoder.querying) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
[reverseGeocoder release];
}
}
2) reverseGeocoder找到答案时调用的委托方法:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
NSString *newSubtitle = [NSString stringWithFormat:@"%@ %@, %@ %@, %@",placemark.subThoroughfare,placemark.thoroughfare,placemark.postalCode,placemark.locality, placemark.country];
Grocery *draggableGrocery = [myMapView.annotations objectAtIndex:0];
draggableGrocery.address = newSubtitle;
self.addressNewGrocery = newSubtitle;
}
有什么想法吗
谢谢 我本来要发布同样的问题,从昨天开始我就一直在寻找同样的问题
更新:
我刚刚想出了一个办法,我不确定这是不是正确的。知道我有一个名为selectedAnnotation的MKAnnotation子类,我只需取消选择,然后在ReverseGeocoder:didFindPlacemark函数中获得新标题后选择该对象:
[mapView deselectAnnotation:selectedAnnotation animated:NO];
[mapView selectAnnotation:selectedAnnotation animated:NO];
对于您的情况,您的代码应该如下所示:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
NSString *newSubtitle = [NSString stringWithFormat:@"%@ %@, %@ %@, %@",placemark.subThoroughfare,placemark.thoroughfare,placemark.postalCode,placemark.locality, placemark.country];
Grocery *draggableGrocery = [myMapView.annotations objectAtIndex:0];
draggableGrocery.address = newSubtitle;
self.addressNewGrocery = newSubtitle;
// add the following lines [I assumed that draggableGrocery [Grocery class] is a subclass of MKAnnotation]
[mapView deselectAnnotation:draggableGrocery animated:NO];
[mapView selectAnnotation:draggableGrocery animated:NO];
}
另一个选项是在启动反向地理编码器之前设置
annotationView.canShowCallout=NO
,然后在完成后将标志设置回YES。谢谢,否则不会起作用。这可能不是最优雅的解决方案,因为旧的标注出现后几乎立即消失,但最好不要更新信息。奇怪的是:我尝试在其他委托函数中使用这些选择和取消选择方法,例如-(void)mapView:(MKMapView*)mapView注释视图:(MKAnnotationView*)注释视图didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState;但是没有效果!你知道为什么吗?是的,我同意我的解决方案不是最好的!实际上,我发布了一个更糟糕的解决方案,然后我编辑了答案,我从mapView中“删除”然后“添加”注释本身,然后选择它。。。好吧,你不能在didChangeDragState方法中做同样的事情!!因为调用信息尚未更改!!它们仅在didFindPlacemark方法中更改;)