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-18-2009, 09:29 PM   #12 (permalink)
PhilSimpson
New Member
 
Join Date: Mar 2009
Posts: 6
Default

Quote:
Originally Posted by David Casseres View Post
I haven't even reached the point of trying to do anything with callouts – all I do is create an instance of a very simple class that implements MKAnnotation, and add it to the map view using addAnnotation:. An exception is immediately thrown from from several frames down in the MapKit code, and it looks like an out-of-bounds index for an NSArray is causing it.

I've also tried using an MKPlacemark object (created by a reverse geocoder) instead of my own custom class, and exactly the same thing happens.
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...
PhilSimpson 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:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.