grgcombs/MultiRowCalloutAnnotationView — Issue #2: Invalid Coordinate crash
Author: kylebuttress
Created: 2012-01-05 06:04:46+00:00
State: open

Hi,

Occasionally I get a crash when the map is moved and the map centre is being re positioned.

with the crash notice

Invalid Coordinate -212.53626430, +486.04761195

Causing the following backtrace

2 CoreFoundation 0x31cf87d3 __handleUncaughtException + 238
3 libobjc.A.dylib 0x34e3606b _objc_terminate + 102
4 libstdc++.6.dylib 0x3442be3d _ZN10__cxxabiv111__terminateEPFvvE + 52
5 libstdc++.6.dylib 0x3442be91 _ZSt9terminatev + 16
6 libstdc++.6.dylib 0x3442bf61 __cxa_throw + 84
7 libobjc.A.dylib 0x34e34c8b objc_exception_throw + 70
8 CoreFoundation 0x31cf83cd -[NSException dealloc] + 0
9 MapKit 0x34781fe3 -[MKMapView setCenterCoordinate:animated:] + 230
10 odpn 0x00072ae1 -[MultiRowCalloutAnnotationView adjustMapRegionIfNeeded] (MultiRowCalloutAnnotationView.m:468)
11 odpn 0x00071f8f -[MultiRowCalloutAnnotationView didMoveToSuperview] (MultiRowCalloutAnnotationView.m:406)
12 UIKit 0x3726c377 -[UIView(Hierarchy) _postMovedFromSuperview:] + 178
13 UIKit 0x372605d7 -[UIView(Hierarchy) removeFromSuperview] + 334
14 MapKit 0x347665c1 -[MKAnnotationContainerView _removeAnnotationView:updateCollections:] + 240
15 MapKit 0x347664c9 -[MKAnnotationContainerView _removeAnnotationView:] + 16
16 MapKit 0x34766243 -[MKAnnotationContainerView removeAnnotation:] + 234
17 MapKit 0x34779517 -[MKMapView removeAnnotation:] + 30

This is the code near 468

//Calculate new center point, if needed
if (xPixelShift || yPixelShift) {
CGFloat pixelsPerDegreeLongitude = self.mapView.frame.size.width / self.mapView.region.span.longitudeDelta;
CGFloat pixelsPerDegreeLatitude = self.mapView.frame.size.height / self.mapView.region.span.latitudeDelta;

CLLocationDegrees longitudinalShift = -(xPixelShift / pixelsPerDegreeLongitude);
CLLocationDegrees latitudinalShift = yPixelShift / pixelsPerDegreeLatitude;

CLLocationCoordinate2D newCenterCoordinate = {self.mapView.region.center.latitude + latitudinalShift, self.mapView.region.center.longitude + longitudinalShift};

[self.mapView setCenterCoordinate:newCenterCoordinate animated:YES];

//fix for now next line 468
self.frame = CGRectMake(self.frame.origin.x - xPixelShift, self.frame.origin.y - yPixelShift, self.frame.size.width, self.frame.size.height);
//fix for later (after zoom or other action that resets the frame)
self.centerOffset = CGPointMake(self.centerOffset.x - xPixelShift, self.centerOffset.y);
}

I'm looking to see if there is a way to over come this.

thanks

Kyle