Skip to content

Instantly share code, notes, and snippets.

@lobrien
Last active December 20, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobrien/6147243 to your computer and use it in GitHub Desktop.
Save lobrien/6147243 to your computer and use it in GitHub Desktop.
Shows a race condition in MapKit. You cannot rely on the map.CenterCoordinate in synchronous code, and it's not clear to me what event (if any) is associated with the `UIMapView.CenterCoordinate` becoming set.
var map = new MKMapView();
var ctr = new CLLocationCoordinate2D(37.8, -122.4);
map.SetCenterCoordinate(ctr, false);
map.SetRegion(new MKCoordinateRegion(ctr, new MKCoordinateSpan(0.025, 0.025)), false);
Console.WriteLine("Center coordinate is still NaN: " + map.CenterCoordinate.Latitude.ToString());
/*
Error: NaN Lat & Long var
circle = MKCircle.Circle(map.CenterCoordinate, 100);
Must use explicit location instead, a la:
*/
var circle = MKCircle.Circle(ctr, 100);
map.AddOverlay(circle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment