<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.2.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MapKit",
  "identifier" : "/documentation/MapKit/MKMapViewDelegate/mapView(_:viewFor:)-8humz",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "MapKit"
    ],
    "preciseIdentifier" : "c:objc(pl)MKMapViewDelegate(im)mapView:viewForAnnotation:"
  },
  "title" : "mapView(_:viewFor:)"
}
-->

# mapView(_:viewFor:)

Returns the view associated with the specified annotation object.

```
optional func mapView(_ mapView: MKMapView, viewFor annotation: any MKAnnotation) -> MKAnnotationView?
```

## Parameters

`mapView`

The map view that requests the annotation view.

`annotation`

The object representing the annotation that the map view is about to display. In addition to your custom annotations, this object might be an [`MKUserLocation`](/documentation/MapKit/MKUserLocation) object representing the user’s location.

## Return Value

The annotation view to display for the specified annotation, or `nil` if you want to display a standard annotation view.

## Discussion

Rather than create a new view each time the map view calls this method, call the [`dequeueReusableAnnotationView(withIdentifier:)`](/documentation/MapKit/MKMapView/dequeueReusableAnnotationView(withIdentifier:)) method of the [`MKMapView`](/documentation/MapKit/MKMapView) class to see if an existing annotation view of the desired type already exists. If one exists, update the returned view to reflect the attributes of the specified annotation and return it. If a view of the appropriate type doesn’t exist, create one, configure it with the needed annotation data, and return it.

If the object in the `annotation` parameter is an instance of the [`MKUserLocation`](/documentation/MapKit/MKUserLocation) class, you can provide a custom view to denote the user’s location. To display the user’s location using the default system view, return `nil`.

If you don’t implement this method, or if you return `nil` from your implementation for annotations other than the user location annotation, the map view uses a standard pin annotation view.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)