如何在地图注释视图中找到 pin id?
如何找到被点击的 pin 的 pin id(即 pin 标题和副标题的详细信息)?
我用它来显示引脚注释。此代码在视图中确实加载:
[resultCoordinate addObjectsFromArray:[sqlClass return_Coordinate]];
if ([resultCoordinate count])
{
for (int i =0; i < [resultCoordinate count]; i++)
{
dict = [resultCoordinate objectAtIndex:i];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[dict objectForKey:@"Lati"] floatValue];
region.center.longitude = [[dict objectForKey:@"Longi"] floatValue];
region.span.longitudeDelta = 0.2f;
region.span.latitudeDelta = 0.2f;
NSString *fishName = [dict objectForKey:@"Fish"];
fishName = [fishName stringByAppendingString:@" "];
NSString *fishWeight = [dict objectForKey:@"Weight"];
fishWeight = [fishWeight stringByAppendingString:@" kg"];
fishName = [fishName stringByAppendingString:fishWeight];
MapAnnotation *ann = [[MapAnnotation alloc] init];
ann.title = fishName;
ann.subtitle = [dict objectForKey:@"DateTime"];
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
}
并在委托中:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
[defaultPinID release];
return pinView;
}
并单击信息按钮:
-(void)infoButtonPressed:(id)sender
{
recordCatch = [[RecordCatchDetails alloc] initWithNibName:@"RecordCatchDetails" bundle:nil];
[self.view addSubview:recordCatch.view] ;
}
其中记录捕获是新的类对象。
How can I find out the pin id (i.e. the details of pin title and subtitle) of pin that was clicked?
I have this to show pins annotations. This code is in view did load:
[resultCoordinate addObjectsFromArray:[sqlClass return_Coordinate]];
if ([resultCoordinate count])
{
for (int i =0; i < [resultCoordinate count]; i++)
{
dict = [resultCoordinate objectAtIndex:i];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[dict objectForKey:@"Lati"] floatValue];
region.center.longitude = [[dict objectForKey:@"Longi"] floatValue];
region.span.longitudeDelta = 0.2f;
region.span.latitudeDelta = 0.2f;
NSString *fishName = [dict objectForKey:@"Fish"];
fishName = [fishName stringByAppendingString:@" "];
NSString *fishWeight = [dict objectForKey:@"Weight"];
fishWeight = [fishWeight stringByAppendingString:@" kg"];
fishName = [fishName stringByAppendingString:fishWeight];
MapAnnotation *ann = [[MapAnnotation alloc] init];
ann.title = fishName;
ann.subtitle = [dict objectForKey:@"DateTime"];
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
}
and in delegate:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
[defaultPinID release];
return pinView;
}
and on click of info button:
-(void)infoButtonPressed:(id)sender
{
recordCatch = [[RecordCatchDetails alloc] initWithNibName:@"RecordCatchDetails" bundle:nil];
[self.view addSubview:recordCatch.view] ;
}
Where record catch is new class object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当注释获取选定的地图视图时,会调用其委托中的
mapView:didSelectAnnotationView:
方法,您可以覆盖此方法以获得所需的内容。如果您想获得附件控制的操作,请单击使用
When annotation gets selected map view calls
mapView:didSelectAnnotationView:
method in its delegate, you can override this to get what you want.If you want to get the action for accessory control click make use of