6

when I try to move MKCircle in my MKMapView I get this error message: -[MKCircle setCoordinate:] unrecognized selector ... But according to the documentation MKCircle conforms to MKAnnotation protocol so it should have setCoordinate: method implemented (in addition Xcode offer me autosuggestion for it and debugger doesn't show any warnings).

Does anyone know where's the problem?

Thanks a lot.

JakubM
  • 2,685
  • 2
  • 23
  • 33

1 Answers1

9

Even though MKCircle does conform to MKAnnotation, the MKCircle class then (unfortunately) overrides the coordinate property as read-only:

The center point of the circular area, specified as a latitude and longitude. (read-only)

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate


The simplest solution is to remove the old overlay with removeOverlay: and add a new one with the new center coordinate and radius.

  • Yes, this property is readonly even in the MKAnnotation protocol but there's also the setter which bypass it. I know that I can remove it and recreate again somewhere else but I use the circle to show location accuracy around custom annotations which mark other people in map and I'd like to animate moving the circle along with the annotation (and of course also enlarging and shrinking of the circle). But overlays should be used to show static data (highlight roads on maps etc.) according the documentation so removing/readding will have to suffice. ;o) Anyway thanks for your answer. – JakubM Jan 26 '11 at 10:28
  • I'm also would like "move" circle overlay instead of just remove it and add because I would like to animate this movement. did you found any solution? – user836026 May 07 '12 at 14:22
  • 1
    @user836026: Yes, you need to create a custom overlay. See my comment on [this question](http://stackoverflow.com/questions/9056451/draw-a-circle-of-1000m-radius-around-users-location-in-mkmapview) for more details. –  May 07 '12 at 14:25
  • I saw the crumbPath example, but I'm not sure how to use it to draw a circle. – user836026 May 08 '12 at 19:03
  • 1
    The LocationReminders app from WWDC 2010 is closer to what you want. It subclasses MKOverlayPathView (instead of MKOverlayView) and in the createPath method, generates a circle using CGPathAddArc. The circle overlay view "moves" by calling invalidatePath when it detects that its associated MKOverlay object's center coordinate or radius has changed (it detects using KVO but you could also monitor in other ways). –  May 08 '12 at 19:28