Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current Location with custom annotation, call-out and blue accuracy circle

After 2 hours of googling I couldn't find an answer so this is my last shot.

I would like to use a custom annotation for the user current location on a mkmapview. But I also want to have the blue accuracy circle around it.

Can this be done?

If not, can I add a call-out to the default blue dot with circle?

The reason that I need this is because on my app, the current location dot often disappears under other annotations. So that's why I use a purple pin with a call-out as current location.

Here is my code for the annotation:

if ([annotation isKindOfClass:MKUserLocation.class]) 
    {
        MKPinAnnotationView *userAnnotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"UserLocation"];
        if (userAnnotationView == nil)  {
            userAnnotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"UserLocation"]autorelease];
        }            
        else 
            userAnnotationView.annotation = annotation;

        userAnnotationView.enabled = YES;
        userAnnotationView.animatesDrop = NO;
        userAnnotationView.pinColor = MKPinAnnotationColorPurple;
        userAnnotationView.canShowCallout = YES;
        [self performSelector:@selector(openCallout:) withObject:annotation afterDelay:0.01];

        return userAnnotationView;  
    }

Thanks for any advise. Cheers, Christian

like image 261
Christian Loncle Avatar asked Jun 19 '10 10:06

Christian Loncle


1 Answers

OK, so I ended up deleting the custom notification but adding a call out that pops up automatically. Like this:

mapView.showsUserLocation=TRUE;
mapView.userLocation.title = NSLocalizedString (@"Here am I",@"Here am I" );
[self performSelector:@selector(openCallout:) withObject:mapView.userLocation afterDelay:3.0];

and:

- (void)openCallout:(id<MKAnnotation>)annotation {
    [mapView selectAnnotation:annotation animated:YES];
}

Without the delay the call-out will not show up.

like image 88
Christian Loncle Avatar answered Oct 06 '22 00:10

Christian Loncle