iPad MapKit - 重新选择一个图钉不起作用
我遇到以下问题:
我的地图上有很多图钉。触摸其中一个后,将打开一个自定义弹出窗口并显示信息。这很完美。
我的问题是,如果您选择同一个图钉两次,弹出窗口不会打开,您必须触摸另一个图钉或单击地图中的某个位置。
我的代码如下:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKAnnotationView* annotationView = nil;
CPPointOfInterest *myAnnotation = (CPPointOfInterest*) annotation;
if ([myAnnotation isKindOfClass:[MKUserLocation class]] || myAnnotation.poi_id <= 0) {
return nil;
} else {
NSString* identifier = @"Pin";
MKPinAnnotationView* annView = (MKPinAnnotationView*)[mv_map dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == annView) {
annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
}
[annView addObserver:self
forKeyPath:@"selected"
options:NSKeyValueObservingOptionNew
context:@"GMAP_ANNOTATION_SELECTED"];
if(self.nearest_poi == myAnnotation) {
annView.pinColor = MKPinAnnotationColorGreen;
} else {
annView.pinColor = MKPinAnnotationColorRed;
}
annView.animatesDrop = YES;
annotationView = annView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:NO];
return annotationView;
}
}
观察者:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context{
NSString *action = (NSString*)context;
if([action isEqualToString:@"GMAP_ANNOTATION_SELECTED"]){
BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
if (annotationAppeared) {
// show popup
}
}
}
我还尝试了 didSelectAnnotationView 方法,这也仅适用于第一次单击事件。
我已经搜索了几个小时,但没有找到...:/
有人知道我的问题的解决方案吗,请给我提示...
谢谢和问候, 马修
I have the following problem:
I have a number of pins on my map. After touching one, a custom popup opens and displays information. This works perfect.
My problem is, that if you select the same pin twice, the popups does not open, you have to touch another one or click some where in the map.
My code is the following:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKAnnotationView* annotationView = nil;
CPPointOfInterest *myAnnotation = (CPPointOfInterest*) annotation;
if ([myAnnotation isKindOfClass:[MKUserLocation class]] || myAnnotation.poi_id <= 0) {
return nil;
} else {
NSString* identifier = @"Pin";
MKPinAnnotationView* annView = (MKPinAnnotationView*)[mv_map dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == annView) {
annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
}
[annView addObserver:self
forKeyPath:@"selected"
options:NSKeyValueObservingOptionNew
context:@"GMAP_ANNOTATION_SELECTED"];
if(self.nearest_poi == myAnnotation) {
annView.pinColor = MKPinAnnotationColorGreen;
} else {
annView.pinColor = MKPinAnnotationColorRed;
}
annView.animatesDrop = YES;
annotationView = annView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:NO];
return annotationView;
}
}
Observer:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context{
NSString *action = (NSString*)context;
if([action isEqualToString:@"GMAP_ANNOTATION_SELECTED"]){
BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
if (annotationAppeared) {
// show popup
}
}
}
I have also tried the didSelectAnnotationView methode, this also just works for the first click event.
I have searched for several hours, but nothing to find... :/
Does anybody knows a solution for my problem, please give me a hint...
Thanks and greetings,
Mathew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须通过mapView取消选择注释,然后才能再次选择它。请尝试以下操作:
You have to deselect the annotation through the mapView before you can select it again. Try the folowing:
我正在使用弹出窗口来显示信息:
I'm using a popover to display the info: