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

Thread: MKAnnotation
View Single Post
Old 07-29-2010, 06:40 PM   #7 (permalink)
Duncan C
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 5,991
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Ovidius View Post
I'm sorry about my previous post, I was looking at the Apple Reference for this protocol and it stated the coordinate as readonly, which gave me problems when assigning its @property and then synthesizing its setters and getters. However:

Basically, I have my class set up as you mention. I tried the following:

Code:
MapAnnotation *startAnnotation = [[MapAnnotation alloc] initWithCoordinate:userLocation.coordinate];
			MKPinAnnotationView *startAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:startAnnotation reuseIdentifier:@"StartPin"];
			startAnnotationPin.pinColor = MKPinAnnotationColorGreen;
			[mapView addAnnotation:startAnnotationPin];
I get this error: warning: class 'MKPinAnnotationView' does not implement the 'MKAnnotation' protocol


You've got the sequence wrong. You create an annotation object and add it to the map. Then, later, the system asks for an annotation view to display that annotation on the map. The code you posted should look like this:

Code:
MapAnnotation *startAnnotation = [[MapAnnotation alloc] 
  initWithCoordinate:userLocation.coordinate];
[mapView addAnnotation: startAnnotation];
Then, you need to add a mapView:viewForAnnotation: method to your map view delegate. That method gets called when the system needs an annotation view to display the annotation you just created.

Something like this:

Code:
- (MKAnnotationView *)mapView:(MKMapView *)mapView
			viewForAnnotation:(id <MKAnnotation>)annotation 
{
  MapAnnotation* theAnnotation = (MapAnnotation*) annotation;
  if(annotation != mapView.userLocation) 
  {
  if ([annotation isKindOfClass: [MapAnnotation class]])
    {
      MKPinAnnotationView *startAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:startAnnotation reuseIdentifier:@"StartPin"];
      startAnnotationPin.pinColor = MKPinAnnotationColorGreen;
      return startAnnotationPin.pinColor;
    }
  }
  else
    return nil;
}

Disclaimer: I banged out the code I'm posting without even checking to make sure it compiles, much less runs without errors. My code rarely compiles the first time, so there are likely syntax errors in the code above.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
 

» Advertisements
» Online Users: 373
10 members and 363 guests
amit.mangal, AyClass, Domele, HemiMG, ipodphone, minglei, online-loans70, Sesio, thephotographer, Wharazhasri
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,568
Threads: 94,081
Posts: 402,751
Top Poster: BrianSlick (7,990)
Welcome to our newest member, online-loans70
Powered by vBadvanced CMPS v3.1.0

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