Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the showUserLocation property of MKMapView

I have an app at the moment which shows various pins on a map. I've tried setting mapView.showsUserLocation = YES; to show the user's current pos, however this crashed my app ("Program received signal: SIGABRT") with the following error message:

Mon Oct 19 12:31:27 unknown Hull Ads[3111] <Error>: *** -[MKUserLocation counter]: unrecognized selector sent to instance 0x10ad60
Mon Oct 19 12:31:27 unknown Hull Ads[3111] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MKUserLocation counter]: unrecognized selector sent to instance 0x10ad60'
Mon Oct 19 12:31:27 unknown Hull Ads[3111] <Error>: Stack: (...)

This is a little confusing as I haven't used MKUserLocation, or is that the problem?

The app does make use of CoreLocation for other non-related purposes however the app responds in the same way when CoreLocation isn't being used already.

If anyone could help that would be awesome!

Thanks - James

like image 986
ingh.am Avatar asked Oct 19 '09 11:10

ingh.am


2 Answers

Be sure to include the following in this method:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation class] == MKUserLocation.class) {
        return nil;
    }
    ...
}

I do hope you've already fixed this by now ;)

like image 86
Berend Avatar answered Oct 05 '22 22:10

Berend


Thanks Berend for answering the question and james.ingham for asking it! I've been looking for a fix for this problem for months and this thread fixed it for me!

Checking for the MKUserLocation pin type would be the most logical thing to do. But who remembers to do that when implementing viewForAnnotation method.. Even if you are not going to use MKuserlocation in your app it would be safe practice to always do this check to avoid running into problems in the future.

like image 36
ravinsp Avatar answered Oct 05 '22 22:10

ravinsp