problem with map annotations (NSInvalidArgumentException)
i am trying to put annotations on my map view. i'm using the WeatherMap sample code from the Apple website. the difference between that code and mine is that my map view is a tab in a tab bar controller. my program is crashing when i click the map tab and i'm getting this error:
*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260
2010-03-22 21:31:26.290 WhereAmI01[1218:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260'
the crash seems to be happening at this line in WeatherAnnotationView.m:
NSInteger high = [weatherItem.high integerValue];
i am trying to put annotations on my map view. i'm using the WeatherMap sample code from the Apple website. the difference between that code and mine is that my map view is a tab in a tab bar controller. my program is crashing when i click the map tab and i'm getting this error:
*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260
2010-03-22 21:31:26.290 WhereAmI01[1218:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260'
the crash seems to be happening at this line in WeatherAnnotationView.m:
NSInteger high = [weatherItem.high integerValue];
what could be the issue?
thanks.
Is that code in your annotation view object? That isn't clear.
I am guessing that your "WeatherItem" is your annotation object?
It looks to me like the object that's returned at the top of the -drawRect method in the line:
It might even be the userLocation annotation object.
Add some checking code:
Code:
id theAnnotation = self.annotation;
if ([theAnnotation class] != [WeatherItem class])
{
NSLog(@"annotation object is not a WeatherItem. class = %@",
[theAnnotation class]);
return;
}
WeatherItem *weatherItem = (WeatherItem *) theAnnotation;
Last edited by Duncan C; 03-28-2010 at 10:28 PM.
Reason: Syntax error
thanks for your response! you were right.. it is an MKUserLocation, not a WeatherItem. with your code, the program no longer crashes. i don't really understand what's going on though. i just integrated the code from the WeatherMap sample code into my own program. i didn't change any of the annotation stuff so how come it's behaving differently in my program vs in the sample?
i'm also confused by the fact that my console printed in this order:
2010-03-28 23:40:34.477 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.478 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:34.480 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.480 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:34.482 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.483 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:34.483 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.484 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:37.451 WhereAmI01[2603:207] annotation object is not a WeatherItem. class = MKUserLocation
thanks Duncan C. I also meet the same problem with Veeplus and my problem is also solved with your advice.
But new problem appears.
I integrate the Apple's sample code "current Address" and " weather Map " together to achieve this: the customer first can find his current address and narrow down to a small range around his current address via this App,then some other POI around him with image annotations ( like in the weather map sample code) appear.
Before using your advice, I have to delete the following code ( otherwise it would be crash and same errors like Veeplus ) :
- (MKAnnotationView *)mapView: (MKMapView *)map viewForAnnotationid <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
WeatherAnnotationView *annotationView =
(WeatherAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:Annota tionViewID];
if (annotationView == nil)
{
annotationView = [[[WeatherAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.annotation = annotation;
return annotationView;
}
--------------
I just leave the following pragma mark Map View Delegate method:
--------------
- (void)mapViewMKMapView *)map regionDidChangeAnimatedBOOL)animated
{
NSArray *weatherItems = [weatherServer weatherItemsForMapRegion:mapView.region maximumCount:4];
[mapView addAnnotations:weatherItems];
}
-------
I achieved this : the customer first can find his current address MARKED with BLUE PIN and narrow down to a small range around his current address via this App, then some other POI around him with just RED PIN appear.
After use your advice and use the deleted code above:
-----
- (MKAnnotationView *)mapViewMKMapView *)map viewForAnnotation: (id <MKAnnotation>)annotation
{static NSString *AnnotationViewID = @"annotationViewID";
WeatherAnnotationView *annotationView =
(WeatherAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:Annota tionViewID];
if (annotationView == nil)
{
annotationView = [[[WeatherAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.annotation = annotation;
return annotationView;
}
------------
the customers first can find his current address and narrow down to a small range around his current address via this App,then some other POI around him with with image annotations. But do not have a marked "BLUE PIN " pointing to his current address.
How can I get customer's current address MARKED with a "BLUE PIN ", at the same time, showing POI around him with image annotations.