문제

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

도움이 되었습니까?

해결책

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];

다른 팁

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
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top