I have many garages and need to show multiple garages in map.
Below is the code I am using for Map to show multiple pins.
CLLocationCoordinate2D annotationCoord;
for (NSMutableDictionary* aDict in Gfeeds) {
annotationCoord.latitude = [aDict[@"GLatitude"] floatValue];
annotationCoord.longitude = [aDict[@"GLongitude"] floatValue];
MKPointAnnotation *annotationPoint2 = [[MKPointAnnotation alloc] init];
annotationPoint2.coordinate = annotationCoord;
annotationPoint2.title = [NSString stringWithFormat:@"%@", aDict[@"GName"]];
annotationPoint2.subtitle = aDict[@"GId"];
[geomapView addAnnotation:annotationPoint2];
}
Now what I wanted is show the details of garage after clicking that map pin… for that I am doing below.
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != geomapView.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[geomapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
//instatiate a detail-disclosure button and set it to appear on right side of annotation
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
return pinAnnotation;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
GarageDetailsViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"GarageDetails"];
secondView.garageMainId = view.annotation.subtitle;
[self.navigationController pushViewController:secondView animated:YES];
}
Using this way I can able to go to GarageDetails, however risk I am taking is showing Id of garage in subtitle. I want to hide this subtitle so that Id would not get displayed.
Any idea how can I do this?
- Hide subtitle
OR
- Pass id to GarageDetails from map...
Why not subclass "
MKPointAnnotation
" (you can name it something like "FahimPointAnnotation
), and in this subclass you can add a "garageID
" property.Then you can add the annotation to your map and when it's clicked on, you can retrieve the annotation and cast the "
MKPointAnnotation
" back to a "FahimPointAnnotation
" and grab your garageID out of it (without having to worry about it appearing in the annotation view's subtitle field).