No problem! Took me a while to figure out that's all I needed to do
and the answers on the StackOverflow question, while informative,
didn't really explain well enough how to do it (at least for an
Objective-C noob like myself).

Glad I could help,

Jeff

On Thu, Sep 15, 2011 at 5:35 PM, Chris Hamblett <[email protected]> wrote:
> Fantastic! This sounds like exactly what I would like it to do! I'll test it
> tonight or tomorrow inside a custom SetCoordinate method. It looks like
> flagging the WillChangeValue and DidChangeValue key to "coordinate" are the
> links to the MapView's KVO I've been looking for. Might want to build this
> into MKAnnotation with a SetAnnotation function in the SDK itself for the
> future to replicate the way Apple does it.
> Thanks,
> ~Chris
>
>> Date: Thu, 15 Sep 2011 17:15:59 -0400
>> Subject: Re: [MonoTouch] Bug 724
>> From: [email protected]
>> To: [email protected]
>> CC: [email protected]
>>
>> Actually... it'd probably be better to put those calls in your
>> SetCoordinate() method that you have, since you probably don't want to
>> make those calls when the MKMapKit (or would it be MKAnnotationView?)
>> calls setCoordinate on your annotation (e.g. when a user drags&drops
>> your annotation view, as hinted at by the Apple docs).
>>
>> Jeff
>>
>> On Thu, Sep 15, 2011 at 4:43 PM, Jeff Stedfast <[email protected]> wrote:
>> > Hi Chris,
>> >
>> > I did some more looking and it turns out the solution is incredibly
>> > simple:
>> >
>> > In your MyAnnotation class, do this:
>> >
>> >                public override CLLocationCoordinate2D Coordinate {
>> >                        get { return  _coord; }
>> >                        set {
>> >                                this.WillChangeValue ("coordinate");
>> >                                _coord = value;
>> >                                this.DidChangeValue ("coordinate");
>> >                        }
>> >                }
>> >
>> > This magically makes the MKMapView redraw your annotation without
>> > having to remove/add the annotation.
>> >
>> > Hope that helps!
>> >
>> > Jeff
>> >
>> > On Thu, Sep 15, 2011 at 1:06 PM, Jeff Stedfast <[email protected]> wrote:
>> >> Turns out people are having the EXACT same issue you are having in
>> >> Objective-C on StackOverflow:
>> >>
>> >>
>> >> http://stackoverflow.com/questions/2256177/how-to-move-a-mkannotation-without-adding-removing-it-from-the-map
>> >>
>> >> You can use this very same trick in MonoTouch.
>> >>
>> >> Jeff
>> >>
>> >> On Thu, Sep 15, 2011 at 12:53 PM, Jeff Stedfast <[email protected]>
>> >> wrote:
>> >>> Hi Chris,
>> >>>
>> >>> Reading the developer documentation on Apple's site for MKAnnotation,
>> >>> this is what it says for setCoordinate:
>> >>>
>> >>> setCoordinate:
>> >>> Sets the new center point of the annotation.
>> >>>
>> >>> - (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate
>> >>> Parameters
>> >>> newCoordinate
>> >>> The new center point for the annotation.
>> >>> Discussion
>> >>> Annotations that support dragging should implement this method to
>> >>> update the position of the annotation.
>> >>>
>> >>> Availability
>> >>> Available in iOS 4.0 and later.
>> >>> Declared In
>> >>> MKAnnotation.h
>> >>>
>> >>>
>> >>> Calling setCoordinate() in Objective-C will not magically make your
>> >>> annotation update its location on the screen. You'll have to use a
>> >>> similar trick as to what I suggested to make it work in Objective-C as
>> >>> well.
>> >>>
>> >>> To the best of my understanding, this method doesn't move the
>> >>> MKAnnotation on the map like you seem to believe, it gets set by the
>> >>> MKMapView when the user drags the annotation to another location.
>> >>>
>> >>> If I'm wrong, please provide me with some documentation explaining why
>> >>> I'm wrong (preferably Apple documentation) or at least an Objective-C
>> >>> program demonstrating it.
>> >>>
>> >>> Jeff
>> >>>
>> >>> On Thu, Sep 15, 2011 at 12:41 PM, Chris Hamblett
>> >>> <[email protected]> wrote:
>> >>>> Since the bug has been changed to resolved without actually solving
>> >>>> the problem, I take this as a good reason that Objective-C will always 
>> >>>> have
>> >>>> functions that cannot be done through MonoTouch. I guess I will be 
>> >>>> making
>> >>>> the switch back to xCode.
>> >>>>
>> >>>> Sent from my iPhone
>> >>>>
>> >>>> On Sep 15, 2011, at 12:19 PM, "Jeff Stedfast" <[email protected]>
>> >>>> wrote:
>> >>>>
>> >>>>> Hi Chris,
>> >>>>>
>> >>>>> I've taken a look at this and the problem is that once an
>> >>>>> MKAnnotationView is created for your MKAnnotation subclass, you are
>> >>>>> doing nothing to signal to the MKMapView that anything has changed.
>> >>>>> Setting a new coordinate on your MKAnnotation subclass has no way of
>> >>>>> notifying the parent MKMapView that it needs to redraw.
>> >>>>>
>> >>>>> Here's what I suggest you do:
>> >>>>>
>> >>>>> In your MKAnnotation subclass (MyAnnotation), add an event that gets
>> >>>>> emitted when you set/change the coordinate. Then, have your
>> >>>>> ViewController that owns the MKMapView listen for those events on
>> >>>>> each
>> >>>>> of your MyAnnotations. When the event is emitted, have your
>> >>>>> ViewController remove the annotation and re-add it.
>> >>>>>
>> >>>>> I tested this and it works.
>> >>>>>
>> >>>>> Jeff
>> >>>>>
>> >>>>> On Thu, Sep 15, 2011 at 9:26 AM, Chris Hamblett
>> >>>>> <[email protected]> wrote:
>> >>>>>> I've added self-contained sample code to Bug 724
>> >>>>>> bug 724
>> >>>>>> Any updates on a binding that sets off the MapView KVO flag? Is
>> >>>>>> this fixed
>> >>>>>> on a new development build?
>> >>>>>> ~Chris
>> >>>>>> _______________________________________________
>> >>>>>> MonoTouch mailing list
>> >>>>>> [email protected]
>> >>>>>> http://lists.ximian.com/mailman/listinfo/monotouch
>> >>>>>>
>> >>>>>>
>> >>>>
>> >>>
>> >>
>> >
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to