我有一个包含2个事件的Map,它们两个的针脚都非常接近。
此代码将检索两个引脚的位置:
// 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:0x280XXXXX,纬度:50.061XXXX,经度:19.93XXXX
当我点击图钉时,它会根据以下代码执行搜索:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"toEventDetails"]){
EventDetailsTableViewController *controller = (EventDetailsTableViewController *)segue.destinationViewController;
controller.Pointfrommap = self.location;
}
}
我的问题:
self.location
来自上述查询(PFQuery)的结果,因此它将保存从查询中获得的最后一个值,但不会保存来自所输入引脚的值
我的猜测:
我知道我可以使用以下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
}
也许我可以在此处添加一些内容,以传递正确的位置。
答案 0 :(得分:0)
您可以尝试
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
AnnotationMap *allEventsAround = (AnnotationMap*)view.annotation;
PFGeoPoint *loc = [PFGeoPoint geoPointWithLatitude:allEventsAround.coordinate.latitude longitude:allEventsAround.coordinate.longitude];
[self performSegueWithIdentifier:@"toEventDetails" sender:loc]; // Use your appropriate segue identifier
}
然后在prepareForSegue
内
controller.Pointfrommap = (PFGeoPoint*) sender;