Bug 724 - MKAnnotation setCoordinate binding, MKMapView KVO
Summary: MKAnnotation setCoordinate binding, MKMapView KVO
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 4.x
Hardware: Macintosh Mac OS
: High major
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-09-10 13:46 UTC by Chris Hamblett
Modified: 2011-09-15 13:08 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Self contained zipped test project showing problem (7.81 MB, application/zip)
2011-09-14 12:41 UTC, Chris Hamblett
Fixed MapViewAnnotationTest.zip (16.60 KB, application/zip)
2011-09-15 12:19 UTC, Jeffrey Stedfast

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chris Hamblett 2011-09-10 13:46:21 UTC
I'm having issues with live updating of a custom MKAnnotation's
coordinates and not having it update in it's MapView unless I issue a zoom
command to it. I've read it is because the MapView uses KVO on the
setCoordinate method in obj-C, so by directly changing the coordinates
through the normal Coordinate binging for MKAnnotation the MapView never
gets flagged to refresh it's location.

I've tried creating a binding for the setCoordinate method, even trying to
use the one I found from Tapku/TKPlace, but I get an invalid selector
exception when I try to run the code. Can we get an updated binding that
causes the MapView's KVO linked flag to be set off when we change the
coordinates of the Annotation?

Comment 1 Jeffrey Stedfast 2011-09-10 15:11:37 UTC
Hey Chris, it looks like this is already implemented as the Coordinate property on MKAnnotation.

if you do annotation.Coordinate = value, does that work?
Comment 2 Sebastien Pouliot 2011-09-12 07:51:51 UTC
Please always provide:

a) the exact version of MonoTouch you're using. It help us detect if something might already been fixed in a more recent version (e.g. beta / alpha);

b) some code sample, you're using, that fails for you. A self contained test case is even better since it will allow us to confirm if it's already fixed or to ensure any fix we make is solving your exact issue.

c) any other revelant links, e.g. "I've read it is because the MapView uses KVO on the setCoordinate method in obj-C".

Comment 3 Chris Hamblett 2011-09-12 09:51:33 UTC
Using latest Beta build as of 9-12-11(MonoDevelop 2.8, MonoTouch 4.2, Mono 2.12)


public void SetCoordinate(CLLocationCoordinate2D coordinate)
    this.Coordinate = coordinate;

This binding changed the coordinate, but was not redrawn/updated in the mapview until after a zoom gesture.

Sample code to come shortly.

Links referring to the KVO in MapView:


Comment 4 Chris Hamblett 2011-09-14 12:41:46 UTC
Created attachment 364 [details]
Self contained zipped test project showing problem

Self contained zipped test project showing problem
Comment 5 Chris Hamblett 2011-09-15 09:22:39 UTC
Changing back to in-progress
Comment 6 Jeffrey Stedfast 2011-09-15 12:19:03 UTC
Created attachment 384 [details]
Fixed MapViewAnnotationTest.zip

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.

Another option might be to signal to the MKAnnotationView and have it call SetNeedsDisplay(). Not sure that'll work, but it might.
Comment 7 Jeffrey Stedfast 2011-09-15 13:08:49 UTC
I found this solution on StackOverflow which uses a trick similar to what I was hinting at as an alternative solution: