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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-22-2009, 08:23 PM   #13 (permalink)
David Casseres
Registered Member
 
Join Date: Nov 2008
Posts: 10
Default

Quote:
Originally Posted by PhilSimpson View Post
OK, here's my AnnotationListObject.h file:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface AnnotationListObject : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
- (void) moveAnnotation: (CLLocationCoordinate2D) newCoordinate;
@end


And the AnnotationListObject.m file:

#import "AnnotationListObject.h"

@implementation AnnotationListObject

@synthesize coordinate, title, subtitle;

- (void) moveAnnotation: (CLLocationCoordinate2D) newCoordinate {
coordinate = newCoordinate;
}

@end


and the relevant calls from RootViewController:

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
MKPinAnnotationView *pin = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier: [annotation title]];
if (pin == nil)
{
pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: [annotation title]] autorelease];
}
else
{
pin.annotation = annotation;
}
pin.pinColor = MKPinAnnotationColorGreen;
pin.animatesDrop = YES;
pin.canShowCallout = TRUE;
return pin;
}

- (void) doAnnotations { // call this from viewDidAppear or somesuch
NSMutableArray annotationList = [NSMutableArray new];
// create loop here if necessary
AnnotationListObject *newAnnotation = [AnnotationListObject new];
CLLocationCoordinate2D tempCoordinate;
tempCoordinate.latitude = 0.0; // set latitude to required value
tempCoordinate.longitude = 0.0; // set longitude to required value
[newAnnotation setCoordinate: tempCoordinate];
[newAnnotation setTitle: @"Title"]; // or whatever
[newAnnotation setSubtitle: @"Subtitle"]; // or whatever
[annotationList addObject: newAnnotation];
newAnnotation release];
// end loop here if looped
[map addAnnotations: annotationList];
}

this is all assuming you have an MKMapView called 'map' correctly connected in Interface Builder. Import the 'AnnotationViewList.h' in the RootViewController file and it should behave. It does for me. Now, if only I could get setRegion:animated: to behave...

It turns out my problem was very simple: I was not setting a delegate for the MKMapView. It seems a bit rude for the MapKit to throw an exception for that, but the whole thing was my mistake.

Thanks for your sample code, which may help me even though my problem was something else.
David Casseres is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,868
Threads: 89,225
Posts: 380,691
Top Poster: BrianSlick (7,129)
Welcome to our newest member, stokesreece
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:17 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.