Question

How to show the user location icon(blue dot) on the top of the map view pin image. Now the user location icon is hidden by the pin image.(below the pin image).

How to do this task ?(check screenshot)

Is it possible to show the user location icon on the top of the image ?

Thank you. enter image description here

Was it helpful?

Solution

You can fetch the annotation for the userLocation and bring his view to front.

MKAnnotationView *annotationView = [self.mapView viewForAnnotation:self.mapView.userLocation];
[annotationView.superView bringSubviewToFront:annotationView];

OTHER TIPS

This is probably happening because you are overriding the userLocation's annotation view.

On the Map View delegate method - mapView:viewForAnnotation:, you can do this:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
  <YourAnnotationViewClass> *annotationView = nil;

  if (annotation != [mapView userLocation]) {
    // Add custom annotation view
  }

  return annotationView;
}

In the case where annotation == [mapView userLocation], if you return nil, the default annotation (the blue circle, in this case) will be used.

    public func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
        if (annotation is MKUserLocation) {
            return nil
        }
        var annotationView: MKAnnotationView?
        // personalize annotationView
        return annotationView
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top