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