我的地图上有多针(适用于餐馆),我想直接在一个视图控制器上,它会显示餐厅的详细信息(每个餐厅都有一个ID)。
目标:当我点击餐馆别针时,我想去那个细节ViewController(加载该餐厅的id)
这是我的代码
-(void)addAnnotationAtLat: (float)lat long:(float)longi titreEvent:(NSString *)titre sousTitreEvent:(NSString *)sousTitre
{
MKCoordinateRegion Bridge = { {0.0, 0.0} , {0.0, 0.0} };
Bridge.center.latitude = lat;
Bridge.center.longitude = longi;
Bridge.span.longitudeDelta = 0.01f;
Bridge.span.latitudeDelta = 0.01f;
MKPointAnnotation *ann = [[MKPointAnnotation alloc] init];
ann.title = titre;
ann.subtitle = sousTitre;
ann.coordinate = Bridge.center;
[_mapResto addAnnotation:ann];
}
-(void)placeRestaurantSurLaCarte: (NSTimer *)timer{
PFQuery *query = [PFQuery queryWithClassName:@"Restaurant"];
self.restauArray = [[query whereKey:@"adresse" nearGeoPoint:self.point withinKilometers:100] findObjects];
for (PFObject *restau in self.restauArray) {
NSArray *boxes = restau[@"boxes"];
PFGeoPoint *coordinate = restau[@"adresse"];
[self addAnnotationAtLat:coordinate.latitude long:coordinate.longitude titreEvent:restau[@"nom"] sousTitreEvent:[NSString stringWithFormat:@"Nombre de boxe disponible :%lu",(unsigned long)boxes.count]];
}
你能帮我一下吗?
答案 0 :(得分:0)
实现以下委托方法:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// get the annotation object
id annotation = view.annotation; // replace id with with your annotation class
// get the id
NSInteger whateverID = annotation.whateverID;
// create the detailviewcontroller
UIViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"STORYBOARDIDENTIFIER"];
detailViewController.whateverID = whateverID;
// push the detailviewcontroller
[self.navigationController pushViewController:detailViewController animated:YES];
}
答案 1 :(得分:0)
您需要实施GMSMapViewDelegate
,特别是此方法
mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool
当你创建别针时,给他们一些你可以在pin.userData
财产中使用的信息。
在您刚刚实现的方法中,调用performSegueWithIdenfier
并将值传递给
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)