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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 09-10-2011, 03:18 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 67
gbenna is on a distinguished road
Default an image for each pin in leftCalloutAccessoryview

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
gbenna is offline   Reply With Quote
Old 10-23-2011, 10:46 AM   #2 (permalink)
Registered Member
 
keeshux's Avatar
 
Join Date: Aug 2011
Location: Italy
Posts: 50
keeshux is on a distinguished road
Default

Next time please enclose your code in the code tags to help us helping you.

As to the code, a quick solution is adding another property to your Area_One class, such as 'calloutView'.

In 'viewDidLoad' you will set a different 'calloutView' for each annotation.

In the delegate method 'viewForAnnotation' you will then cast the annotation parameter to a more meaningful Area_One object and get the 'calloutView' property. Finally you set the pinView.leftCalloutAccessoryView to the annotation.calloutView value.

Anyway, you'd better write another MKAnnotation implementation class instead of Area_One. Using an UIViewController as an annotation is avoidable.
__________________
Website: http://algoritmico.com
Twitter: http://twitter.com/keeshux
GitHub: http://github.com/keeshux
keeshux is offline   Reply With Quote
Old 10-23-2011, 10:46 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 1
STATU5one is on a distinguished road
Default

Quote:
Originally Posted by gbenna View Post
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


You could put a conditional inside your viewForAnnotation method, which checks a value for something, and returns the correct image for whatever image you want for that value
STATU5one is offline   Reply With Quote
Reply

Bookmarks

Tags
annotation, call out, leftcalloutaccessoryview, mapkit

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: 376
8 members and 368 guests
bignoggins, epaga, hussain1982, LunarMoon, omagod, Paul10, pinacate, skog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,860
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

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