【发布时间】:2011-07-26 16:09:04
【问题描述】:
我有一个地图视图,上面显示了一些 Pin 注释。我还使用了这些图钉上的标注,所以现在当有人点击这些图钉时,会出现一个标注,其中包含该位置的详细信息,现在我想识别标注并推送另一个特定于该图钉的视图。 代码如下:
-(void)configureView:(NSDictionary *)serverResult {
// Get the set of projects from the project list
[spinner stopAnimating];
NSSet * projects = [[serverResult valueForKey:@"Map"] valueForKey:@"projects"];
NSLog(@"Map got %d projects", projects.count);
mapView.showsUserLocation = YES;
mapView.delegate = self;
MKCoordinateRegion newRegion;
MKCoordinateSpan span;
span.latitudeDelta=130.0;
span.longitudeDelta=130.0;
collection = [[NSMutableArray alloc]init];
// Iterate over the set of projects
for (NSManagedObject *project in projects) {
// Get the set of locations for the current project
NSSet *locations = [project valueForKey:@"locations"];
int i =0;
for (NSManagedObject *location in locations) {
NSString * projectId = [projects valueForKey:@"id"];
NSString * lat = [location valueForKey:@"latitude"];
double lati = [lat doubleValue];
NSString * lang = [location valueForKey:@"longitude"];
double longi = [lang doubleValue];
CLLocationCoordinate2D annotation = mapView.userLocation.coordinate;
annotation.latitude= lati;
annotation.longitude= longi;
newRegion.span=span;
newRegion.center=annotation;
geoCoder=[[MKReverseGeocoder alloc] initWithCoordinate:annotation];
geoCoder.delegate=self;
[geoCoder start];
[self.mapView setRegion:newRegion animated:YES];
i= i +1;
}
}
[self.view addSubview:mapView];
[self.view addSubview:segments];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
NSLog(@"Reverse Geocoder Errored");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
NSLog(@"Reverse Geocoder completed");
mPlacemark=placemark;
[mapView addAnnotation:placemark];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.animatesDrop=TRUE;
annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.canShowCallout = YES;
annView.enabled = YES;
return annView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
AllDetailDashboard *summary = [[AllDetailDashboard alloc] initWithNibName:@"View Controller" bundle:nil];
//Want to write some code here to recognize which project is clicked, in AllDetailDashBoard class we have a variable called project id which is used to recognize the project but i am not able to fetch the project id for specific project which is clicked here
[self.navigationController pushViewController:summary animated:YES];
[summary release];
}
我需要使用任何其他委托方法来识别标注。 现在点击标注我想将 projectId 发送到 AllDetailDashBoard。
谢谢,
【问题讨论】:
-
你是如何创建注释的?它们是否来自链接到您的项目的数组?如果是这样,这将是一个相当简单的修复
标签: iphone objective-c mkmapview