【发布时间】:2018-11-04 21:51:32
【问题描述】:
我有一个包含 2 个事件的地图,它们的引脚彼此非常接近。
此代码将检索两个引脚的位置:
// This query is used to get the location of all events in the parse cloud database
PFQuery *locationQuery = [PFQuery queryWithClassName:@"Event"];
[locationQuery whereKeyExists:@"EventLocation"];
[locationQuery whereKey:@"Organizator" notEqualTo:PFUser.currentUser.username];
[locationQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// All the locations are stored in the objects NSArray
for (PFObject *gp in objects) {
// We store all the found locations in a PFGeoPoint object and then we have to transform this PFGeoPoints in real latitude/longitude coordinates via the CLLocationCoordinate2DMake method
self.location = [gp objectForKey:@"EventLocation"];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.location.latitude, self.location.longitude);
// Subclass of MKAnnotation
AnnotationMap *AllEventsAround = [[AnnotationMap alloc]init];
AllEventsAround.coordinate = coordinate; // We assign the coordinates got in CLLocationCoordinate2DMake to the coordinates of the AnnotationMap class
AllEventsAround.title = [gp valueForKey:@"SportName"];
AllEventsAround.subtitle = [NSString stringWithFormat:@"%@",[gp valueForKey:@"DateAndTime"]];
// method call to point the annotations on the map
[self.EventsmapMapView addAnnotation:AllEventsAround];
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
检索工作正常。一个例子可以是:
=> PFGeoPoint:0x2805XXXX,纬度:50.XXXXX,经度:19.XXXXX
=> PFGeoPoint:0x280XXXX,纬度:50.061XXXX,经度:19.93XXXX
当我点击一个 pin 时,它会根据此代码执行 segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"toEventDetails"]){
EventDetailsTableViewController *controller = (EventDetailsTableViewController *)segue.destinationViewController;
controller.Pointfrommap = self.location;
}
}
我的问题:
self.location来自上述查询(PFQuery)的结果,因此它会保存从查询中获得的最后一个值,而不是来自一个pin tap的值
我的猜测:
我知道我可以使用这个 Delegate 方法:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
//In case a pin is selected, we perform a segue to the event's detail view. On the segue, the actual event coordinates are stored in tappedCoord and send to the details view controller
[self performSegueWithIdentifier:@"toEventDetails" sender:self]; // Use your appropriate segue identifier
}
也许我可以在此处添加一些内容以传递正确的位置。
【问题讨论】:
标签: ios objective-c mkmapview segue mkannotation