Reputation: 11
I've got a mapView and Annotation view that drops pins on a region based on the long/lat for a series of objects representing physical branches. I've got a callout for the annotations that is prompting to open the shared application Maps to give them directions from their location.. but, I can't figure out how to get the address from the branch object/annotation and pass it when the CalloutAccessoryControlTapped fires:
Branch objects:
CLLocationCoordinate2D newCord;
newCord.latitude = 34.0038;
newCord.longitude = -84.0965;
corp = [[LocationwithAnnotation alloc] initWithCoordinate:newCord];
corp.mTitle = @"Corp Office";
corp.mSubTitle = @"123 Main Street, Duluth GA";
[mapView addAnnotation:corp];
[corp release];
newCord.latitude = 33.0038;
newCord.longitude = -84.3965;
uga = [[LocationwithAnnotation alloc] initWithCoordinate:newCord];
uga.mTitle = @"uga Office";
uga.mSubTitle = @"123 Main Street, Atlanta GA";
[mapView addAnnotation:uga];
[corp release];
These annotations are added to the map, then when the callout is hit, I want to be able tp push them to the maps app with the selected annotation's (corp, for example) subtitle.
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
NSLog(@"%@", mapView.selectedAnnotations);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Directions"
message:@"Get directions to this branch?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles: @"Yes, please", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
MKUserLocation *loc = mapView.userLocation.location;
double latitude = loc.location.coordinate.latitude;
NSString *lat = [NSString stringWithFormat:@"%f",latitude];
double longitude = loc.location.coordinate.longitude;
NSString *lon = [NSString stringWithFormat:@"%f",longitude];
NSString *base = @"http://maps.google.com/maps?";
NSString *dest = [@"daddr=" stringByAppendingString: mapView.SelectedAnnotations; // Doesn't work.
The only thing my NSLog is dumping is just the memory address for the SelectedAnnotation.. so how can I grab the object from that?
Upvotes: 1
Views: 1137
Reputation: 103
for(YourMKAnnotationProtocolClass *object in _mapView.selectedAnnotation){
NSLog("%@", object.title); // or you can access other information you've defined
}
Upvotes: 2
Reputation: 46965
If you insist on using an AlertView here, instead of directly utilizing calloutAccessoryControlTapped, I would just add the selected Annotation's subtitle to the alertView's meessage and then parse that in clickedButtonAtIndex method
Upvotes: 0