Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2011, 03:48 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 67
gbenna is on a distinguished road
Default adding image to annotation call out in map view

I have an app which uses map view. I have four locations with pins which have a title and subtitle in the call out. I have been able to add a view to leftCalloutAnnotationView but I would like to have a different view for each ppin, does anyone know how to do this? Maybe tie it to the title? Here is my code for .h and .m.


#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MKAnnotationView.h>


@interface Area_One : UITableViewController <MKMapViewDelegate, MKAnnotation>{

CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;


NSArray *tableData;

MKMapView *mapView;

}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic) BOOL animatesDrop;
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) NSArray *tableData;

@end




#import "Area One.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "Location Two.h"
#import "GroupStudioThree.h"
#import "TableViewPushAppDelegate.h"
@implementation Area_One

-(id) init{
if((self = [super initWithNibName:@"Area One" bundle:nil])){

}
return self;
}


@synthesize tableData;
@synthesize mapView;
@synthesize coordinate,title,subtitle, animatesDrop;

#pragma mark -
#pragma mark Dealloc and Memory Methods

- (void)viewDidLoad {
[super viewDidLoad];

NSString *path = [[NSBundle mainBundle] pathForResource:@"TableData" ofType:@"plist"];
self.tableData = [NSArray arrayWithContentsOfFileath];

[mapView setMapType:MKMapTypeHybrid];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0,0.0}, {0.0,0.0} };
region.center.latitude = 32.041586 ;
region.center.longitude = -110.773945;
region.span.longitudeDelta = 0.10f;
region.span.latitudeDelta = 0.10f;
[mapView setRegion:region animated:YES];

[mapView setDelegate:self];

Area_One *ann = [[Area_One alloc] init];
ann.title = @"Main Entrance";
ann.subtitle = @"Houghton Road";
ann.coordinate = region.center;
[mapView addAnnotation:ann];

MKCoordinateRegion region1 = { {0.0,0.0}, {0.0,0.0} };
region1.center.latitude = 32.048716 ;
region1.center.longitude = -110.782356;
region1.span.longitudeDelta = 0.10f;
region1.span.latitudeDelta = 0.10f;
[mapView setRegion:region1 animated:YES];

[mapView setDelegate:self];

Area_One *ann1 = [[Area_One alloc] init];
ann1.title = @"North Entrance";
ann1.subtitle = @"Brekke Road";
ann1.coordinate = region1.center;
[mapView addAnnotation:ann1];

MKCoordinateRegion region2 = { {0.0,0.0}, {0.0,0.0} };
region2.center.latitude = 32.042077 ;
region2.center.longitude = -110.790854;
region2.span.longitudeDelta = 0.10f;
region2.span.latitudeDelta = 0.10f;
[mapView setRegion:region2 animated:YES];

[mapView setDelegate:self];

Area_One *ann2 = [[Area_One alloc] init];
ann2.title = @"West Entrance";
ann2.subtitle = @"Harrison Road";
ann2.coordinate = region2.center;
[mapView addAnnotation:ann2];

MKCoordinateRegion region3 = { {0.0,0.0}, {0.0,0.0} };
region3.center.latitude = 32.044064 ;
region3.center.longitude = -110.781552;
region3.span.longitudeDelta = 0.10f;
region3.span.latitudeDelta = 0.10f;
[mapView setRegion:region3 animated:YES];

[mapView setDelegate:self];

Area_One *ann3 = [[Area_One alloc] init];
ann3.title = @"Main Ticket Entrance";
ann3.subtitle = @"Houghton Parking Area";
ann3.coordinate = region3.center;
[mapView addAnnotation:ann3];


}

-(MKAnnotationView *)mapViewMKMapView *) mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation !=mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:defaul tPinID];
if (pinView == nil) pinView = [[[MKPinAnnotationView alloc]

initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;

UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"VisualOne.png"]];
myImageView.frame = CGRectMake (0,0,31,31);
pinView.leftCalloutAccessoryView = myImageView;
[myImageView release], myImageView = nil;

}
else {
[mapView.userLocation setTitle:@"I am here"];

}
return pinView;



self.title = @"Entrances";
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}


- (void)dealloc {
/*
[imagesArray release];
[array release];
*/
[super dealloc];
}


@end

Last edited by gbenna; 09-29-2011 at 05:15 PM. Reason: answered own question have another
gbenna is offline   Reply With Quote
Reply

Bookmarks

Tags
annotation, call out, image annotation, map view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 405
10 members and 395 guests
apatsufas, Eclectic, fiftysixty, JackReidy, jeroenkeij, teebee74, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0