Protocol: MKMapViewDelegate
Overview
The MKMapViewDelegate protocol defines a set of optional methods that you can use to receive map-related update messages. Because many map operations require the MKMapView class to load data asynchronously, the map view calls these methods to notify your application when specific operations complete. The map view also uses these methods to request annotation and overlay views and to manage interactions with those views. Tells the delegate that the user tapped one of the annotation view’s accessory buttons.Tells the delegate that the drag state of one of its annotation views changed.Tells the delegate that one or more annotation views were added to the map.Tells the delegate that one or more overlay views were added to the map.Tells the delegate that the user tracking mode changed. (required)Tells the delegate that one of its annotation views was deselected.Tells the delegate that an attempt to locate the user’s position failed.Tells the delegate that one of its annotation views was selected.Tells the delegate that the location of the user was updated.Tells the delegate that the region displayed by the map view just changed.Tells the delegate that the region displayed by the map view is about to change.Returns the view associated with the specified annotation object. Asks the delegate for the overlay view to use when displaying the specified overlay object.Tells the delegate that the specified view was unable to load the map data.Tells the delegate that the specified map view successfully loaded the needed map data. Tells the delegate that the map view stopped tracking the user’s location.Tells the delegate that the specified map view is about to retrieve some map data.Tells the delegate that the map view will start tracking the user’s position.
Instance Method Summary (collapse)
-
- mapView:annotationView:calloutAccessoryControlTapped:
Tells the delegate that the user tapped one of the annotation view’s accessory buttons.
-
- mapView:annotationView:didChangeDragState:fromOldState:
Tells the delegate that the drag state of one of its annotation views changed.
-
- mapView:didAddAnnotationViews:
Tells the delegate that one or more annotation views were added to the map.
-
- mapView:didAddOverlayViews:
Tells the delegate that one or more overlay views were added to the map.
-
- mapView:didChangeUserTrackingMode:animated:
Tells the delegate that the user tracking mode changed.
-
- mapView:didDeselectAnnotationView:
Tells the delegate that one of its annotation views was deselected.
-
- mapView:didFailToLocateUserWithError:
Tells the delegate that an attempt to locate the user’s position failed.
-
- mapView:didSelectAnnotationView:
Tells the delegate that one of its annotation views was selected.
-
- mapView:didUpdateUserLocation:
Tells the delegate that the location of the user was updated.
-
- mapView:regionDidChangeAnimated:
Tells the delegate that the region displayed by the map view just changed.
-
- mapView:regionWillChangeAnimated:
Tells the delegate that the region displayed by the map view is about to change.
-
- mapView:viewForAnnotation:
Returns the view associated with the specified annotation object.
-
- mapView:viewForOverlay:
Asks the delegate for the overlay view to use when displaying the specified overlay object.
-
- mapViewDidFailLoadingMap:withError:
Tells the delegate that the specified view was unable to load the map data.
-
- mapViewDidFinishLoadingMap:
Tells the delegate that the specified map view successfully loaded the needed map data.
-
- mapViewDidStopLocatingUser:
Tells the delegate that the map view stopped tracking the user’s location.
-
- mapViewWillStartLoadingMap:
Tells the delegate that the specified map view is about to retrieve some map data.
-
- mapViewWillStartLocatingUser:
Tells the delegate that the map view will start tracking the user’s position.
Instance Method Details
- (Object) mapView(mapView, annotationView:view, calloutAccessoryControlTapped:control)
Tells the delegate that the user tapped one of the annotation view’s accessory buttons. Accessory views contain custom content and are positioned on either side of the annotation title text. If a view you specify is a descendant of the UIControl class, the map view calls this method as a convenience whenever the user taps your view. You can use this method to respond to taps and perform any actions associated with that control. For example, if your control displayed additional information about the annotation, you could use this method to present a modal panel with that information.If your custom accessory views are not descendants of the UIControl class, the map view does not call this method.
- (Object) mapView(mapView, annotationView:annotationView, didChangeDragState:newState, fromOldState:oldState)
Tells the delegate that the drag state of one of its annotation views changed. The drag state typically changes in response to user interactions with the annotation view. However, the annotation view itself is responsible for changing that state as well.
- (Object) mapView(mapView, didAddAnnotationViews:views)
Tells the delegate that one or more annotation views were added to the map. By the time this method is called, the specified views are already added to the map.
- (Object) mapView(mapView, didAddOverlayViews:overlayViews)
Tells the delegate that one or more overlay views were added to the map. By the time this method is called, the specified views are already added to the map.
- (Object) mapView(mapView, didChangeUserTrackingMode:mode, animated:animated)
Tells the delegate that the user tracking mode changed. (required)
- (Object) mapView(mapView, didDeselectAnnotationView:view)
Tells the delegate that one of its annotation views was deselected. You can use this method to track changes in the selection state of annotation views.
- (Object) mapView(mapView, didFailToLocateUserWithError:error)
Tells the delegate that an attempt to locate the user’s position failed.
- (Object) mapView(mapView, didSelectAnnotationView:view)
Tells the delegate that one of its annotation views was selected. You can use this method to track changes in the selection state of annotation views.
- (Object) mapView(mapView, didUpdateUserLocation:userLocation)
Tells the delegate that the location of the user was updated. While the showsUserLocation property is set to YES, this method is called whenever a new location update is received by the map view. This method is also called if the map view’s user tracking mode is set to MKUserTrackingModeFollowWithHeading and the heading changes.This method is not called if the application is currently running in the background. If you want to receive location updates while running in the background, you must use the Core Location framework.
- (Object) mapView(mapView, regionDidChangeAnimated:animated)
Tells the delegate that the region displayed by the map view just changed. This method is called whenever the currently displayed map region changes. During scrolling, this method may be called many times to report updates to the map position. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting scrolling performance.
- (Object) mapView(mapView, regionWillChangeAnimated:animated)
Tells the delegate that the region displayed by the map view is about to change. This method is called whenever the currently displayed map region changes. During scrolling, this method may be called many times to report updates to the map position. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting scrolling performance.
- (MKAnnotationView) mapView(mapView, viewForAnnotation:annotation)
Returns the view associated with the specified annotation object. Rather than create a new view each time this method is called, you should use the dequeueReusableAnnotationViewWithIdentifier: method of the MKMapView class to see if an existing annotation view of the desired type already exists. If one does exist, you should update the view to reflect the attributes of the specified annotation and return it. If a view of the appropriate type does not exist, you should 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 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 do not 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.
- (MKOverlayView) mapView(mapView, viewForOverlay:overlay)
Asks the delegate for the overlay view to use when displaying the specified overlay object. If you support the presentation of overlays, you must implement this method and provide the views for your overlay objects.
- (Object) mapViewDidFailLoadingMap(mapView, withError:error)
Tells the delegate that the specified view was unable to load the map data. This method might be called in situations where the device does not have access to the network or is unable to load the map data for some reason. It may also be called if a request for additional map tiles comes in while a previous request for tiles is still pending. You can use this message to notify the user that the map data is unavailable.
- (Object) mapViewDidFinishLoadingMap(mapView)
Tells the delegate that the specified map view successfully loaded the needed map data. This method is called when the map tiles associated with the current request have been loaded. Map tiles are requested when a new visible area is scrolled into view and tiles are not already available. Map tiles may also be requested for portions of the map that are not currently visible. For example, the map view may load tiles immediately surrounding the currently visible area as needed to handle small pans by the user.
- (Object) mapViewDidStopLocatingUser(mapView)
Tells the delegate that the map view stopped tracking the user’s location. This method is called when the value of the showsUserLocation property changes to NO.
- (Object) mapViewWillStartLoadingMap(mapView)
Tells the delegate that the specified map view is about to retrieve some map data. This method is called whenever a new group of map tiles need to be downloaded from the server. This typically occurs whenever you expose portions of the map by panning or zooming the content. You can use this method to mark the time that it takes for the map view to load the data.
- (Object) mapViewWillStartLocatingUser(mapView)
Tells the delegate that the map view will start tracking the user’s position. This method is called when the value of the showsUserLocation property changes to YES.