Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapView: how to bring MKUserLocationView (The blue dot) to front?

I am adding a custom annotation instead of the pin annotation. Basically, I draw a circle in these annotations and add them to the map. THe problem these custom annotations obscure the user location view ( the blue dot) How do I bring the blue dot to the front.

- (void)mapView:(MKMapView *)mapView 
didUpdateUserLocation:(MKUserLocation *)userLocation 
{
UIView *user = [mapView viewForAnnotation:userLocation];
[mapView bringSubviewToFront:user];
}

However, this is not working for me. The blue user dot is still being covered by my custom annotations. Any ideas how I can get the user location view to appear in front? Cheers

like image 749
qutaibah Avatar asked Dec 18 '25 04:12

qutaibah


2 Answers

Try this, it works.:

MKAnnotationView *userLocationView = [self.mapView viewForAnnotation:self.mapView.userLocation];
[userLocationView.superview bringSubviewToFront:userLocationView];
like image 174
Sonny Saluja Avatar answered Dec 20 '25 21:12

Sonny Saluja


I accomplished it like this:

- (void) mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views {
    for (MKAnnotationView *view in views) {
        if ([[view annotation] isKindOfClass:[MKUserLocation class]]) {
            [[view superview] bringSubviewToFront:view];
        } else {
            [[view superview] sendSubviewToBack:view];
        }
    }
}
like image 41
jmcopeland Avatar answered Dec 20 '25 21:12

jmcopeland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!